]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
dns scavenging: avoid leak in dns_tombstone_records
authorDouglas Bagnall <douglas.bagnall@catalyst.net.nz>
Tue, 13 Apr 2021 04:31:10 +0000 (16:31 +1200)
committerAndrew Bartlett <abartlet@samba.org>
Sun, 20 Jun 2021 23:26:32 +0000 (23:26 +0000)
As always, we forget to free our zones. Also to check our zones.

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 1d8cb2213c689fe881c18b105db7bcb2b57b6091..6865cedd18773099e869672d2e7b7f33534ae4e1 100644 (file)
@@ -336,23 +336,32 @@ NTSTATUS dns_tombstone_records(TALLOC_CTX *mem_ctx,
        unix_to_nt_time(&entombed_time, unix_now);
        dns_timestamp = unix_to_dns_timestamp(unix_now);
 
+       tmp_ctx = talloc_new(mem_ctx);
+       if (tmp_ctx == NULL) {
+               return NT_STATUS_NO_MEMORY;
+       }
+
+       ret = dns_common_zones(samdb, tmp_ctx, NULL, &zones);
+       if (!NT_STATUS_IS_OK(ret)) {
+               TALLOC_FREE(tmp_ctx);
+               return ret;
+       }
 
-       dns_common_zones(samdb, mem_ctx, NULL, &zones);
        for (z = zones; z; z = z->next) {
-               tmp_ctx = talloc_new(NULL);
                ret = dns_tombstone_records_zone(tmp_ctx,
                                                 samdb,
                                                 z,
                                                 dns_timestamp,
                                                 entombed_time,
                                                 error_string);
-               TALLOC_FREE(tmp_ctx);
                if (NT_STATUS_EQUAL(ret, NT_STATUS_PROPSET_NOT_FOUND)) {
                        continue;
                } else if (!NT_STATUS_IS_OK(ret)) {
+                       TALLOC_FREE(tmp_ctx);
                        return ret;
                }
        }
+       TALLOC_FREE(tmp_ctx);
        return NT_STATUS_OK;
 }