From: Douglas Bagnall Date: Wed, 14 Apr 2021 05:35:01 +0000 (+1200) Subject: dns scavenging: avoid another small memory leak X-Git-Tag: tevent-0.11.0~297 X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=25be60a1cc4779eee5613e2b3540d29890299a92;p=thirdparty%2Fsamba.git dns scavenging: avoid another small memory leak We weren't freeing the zones, which is admittedly tricky with the dlink list. Signed-off-by: Douglas Bagnall Reviewed-by: Andrew Bartlett --- diff --git a/source4/dsdb/kcc/scavenge_dns_records.c b/source4/dsdb/kcc/scavenge_dns_records.c index 0187d5abe66..4ff46196d79 100644 --- a/source4/dsdb/kcc/scavenge_dns_records.c +++ b/source4/dsdb/kcc/scavenge_dns_records.c @@ -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; }