]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
dns scavenging: avoid another small memory leak
authorDouglas Bagnall <douglas.bagnall@catalyst.net.nz>
Wed, 14 Apr 2021 05:35:01 +0000 (17:35 +1200)
committerAndrew Bartlett <abartlet@samba.org>
Sun, 20 Jun 2021 23:26:32 +0000 (23:26 +0000)
We weren't freeing the zones, which is admittedly tricky with the dlink
list.

Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
source4/dsdb/kcc/scavenge_dns_records.c

index 0187d5abe66edfd587faac4ed22b207ad11fc578..4ff46196d79ffee309ec56eeeecae3e937643d49 100644 (file)
@@ -416,13 +416,17 @@ NTSTATUS dns_delete_tombstones(TALLOC_CTX *mem_ctx,
                return NT_STATUS_INTERNAL_ERROR;
        }
 
-       dns_common_zones(samdb, mem_ctx, NULL, &zones);
-       for (z = zones; z; z = z->next) {
-               tmp_ctx = talloc_new(NULL);
-               if (tmp_ctx == NULL) {
-                       return NT_STATUS_NO_MEMORY;
-               }
+       tmp_ctx = talloc_new(mem_ctx);
+       if (tmp_ctx == NULL) {
+               return NT_STATUS_NO_MEMORY;
+       }
+       status = dns_common_zones(samdb, tmp_ctx, NULL, &zones);
+       if (!NT_STATUS_IS_OK(status)) {
+               TALLOC_FREE(tmp_ctx);
+               return status;
+       }
 
+       for (z = zones; z; z = z->next) {
                /*
                 * This can load a very large set, but on the
                 * assumption that the number of tombstones is
@@ -441,7 +445,6 @@ NTSTATUS dns_delete_tombstones(TALLOC_CTX *mem_ctx,
                                 "(&(objectClass=dnsNode)(dNSTombstoned=TRUE))");
 
                if (ret != LDB_SUCCESS) {
-                       TALLOC_FREE(tmp_ctx);
                        *error_string =
                            talloc_asprintf(mem_ctx,
                                            "Failed to "
@@ -449,6 +452,7 @@ NTSTATUS dns_delete_tombstones(TALLOC_CTX *mem_ctx,
                                            "dns objects in zone %s: %s",
                                            ldb_dn_get_linearized(z->dn),
                                            ldb_errstring(samdb));
+                       TALLOC_FREE(tmp_ctx);
                        return NT_STATUS_INTERNAL_ERROR;
                }
 
@@ -502,7 +506,7 @@ NTSTATUS dns_delete_tombstones(TALLOC_CTX *mem_ctx,
                        }
                }
 
-               TALLOC_FREE(tmp_ctx);
        }
+       TALLOC_FREE(tmp_ctx);
        return NT_STATUS_OK;
 }