diff options
author | Douglas Bagnall <douglas.bagnall@catalyst.net.nz> | 2021-04-11 13:45:19 +1200 |
---|---|---|
committer | Andrew Bartlett <abartlet@samba.org> | 2021-06-20 23:26:32 +0000 |
commit | 4a2bfd249d06e229b080cb6f50a68086a8aa1e52 (patch) | |
tree | 1cedb5187c85e071e63e917118b917833530ed9a | |
parent | 444b8178b8652f6e5273879a7036b23fe0057b37 (diff) | |
download | samba-4a2bfd249d06e229b080cb6f50a68086a8aa1e52.tar.gz |
dns scavenging: avoid useless copy of msg
Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
-rw-r--r-- | source4/dsdb/kcc/scavenge_dns_records.c | 25 |
1 files changed, 4 insertions, 21 deletions
diff --git a/source4/dsdb/kcc/scavenge_dns_records.c b/source4/dsdb/kcc/scavenge_dns_records.c index 6084808ca34..db341364902 100644 --- a/source4/dsdb/kcc/scavenge_dns_records.c +++ b/source4/dsdb/kcc/scavenge_dns_records.c @@ -97,7 +97,6 @@ static NTSTATUS dns_tombstone_records_zone(TALLOC_CTX *mem_ctx, struct ldb_message_element *tombstone_el = NULL; struct ldb_message_element *old_el = NULL; struct ldb_message *new_msg = NULL; - struct ldb_message *old_msg = NULL; enum ndr_err_code ndr_err; int ret; struct GUID guid; @@ -178,28 +177,21 @@ static NTSTATUS dns_tombstone_records_zone(TALLOC_CTX *mem_ctx, * change. This prevents race conditions. */ for (i = 0; i < res->count; i++) { - old_msg = ldb_msg_copy(mem_ctx, res->msgs[i]); - if (old_msg == NULL) { + new_msg = ldb_msg_copy(mem_ctx, res->msgs[i]); + if (new_msg == NULL) { return NT_STATUS_INTERNAL_ERROR; } - old_el = ldb_msg_find_element(old_msg, "dnsRecord"); + old_el = ldb_msg_find_element(new_msg, "dnsRecord"); if (old_el == NULL) { - TALLOC_FREE(old_msg); + TALLOC_FREE(new_msg); return NT_STATUS_INTERNAL_ERROR; } - old_el->flags = LDB_FLAG_MOD_DELETE; - new_msg = ldb_msg_copy(mem_ctx, old_msg); - if (new_msg == NULL) { - TALLOC_FREE(old_msg); - return NT_STATUS_INTERNAL_ERROR; - } ret = ldb_msg_add_empty( new_msg, "dnsRecord", LDB_FLAG_MOD_ADD, &el); if (ret != LDB_SUCCESS) { - TALLOC_FREE(old_msg); TALLOC_FREE(new_msg); return NT_STATUS_INTERNAL_ERROR; } @@ -207,7 +199,6 @@ static NTSTATUS dns_tombstone_records_zone(TALLOC_CTX *mem_ctx, status = copy_current_records(mem_ctx, old_el, el, dns_timestamp); if (!NT_STATUS_IS_OK(status)) { - TALLOC_FREE(old_msg); TALLOC_FREE(new_msg); return NT_STATUS_INTERNAL_ERROR; } @@ -215,7 +206,6 @@ static NTSTATUS dns_tombstone_records_zone(TALLOC_CTX *mem_ctx, /* If nothing was expired, do nothing. */ if (el->num_values == old_el->num_values && el->num_values != 0) { - TALLOC_FREE(old_msg); TALLOC_FREE(new_msg); continue; } @@ -238,7 +228,6 @@ static NTSTATUS dns_tombstone_records_zone(TALLOC_CTX *mem_ctx, struct ldb_val, 1); if (!vals) { - TALLOC_FREE(old_msg); TALLOC_FREE(new_msg); return NT_STATUS_INTERNAL_ERROR; } @@ -255,7 +244,6 @@ static NTSTATUS dns_tombstone_records_zone(TALLOC_CTX *mem_ctx, &true_val, &tombstone_el); if (ret != LDB_SUCCESS) { - TALLOC_FREE(old_msg); TALLOC_FREE(new_msg); return NT_STATUS_INTERNAL_ERROR; } @@ -268,7 +256,6 @@ static NTSTATUS dns_tombstone_records_zone(TALLOC_CTX *mem_ctx, struct ldb_val, 1); if (!vals) { - TALLOC_FREE(old_msg); TALLOC_FREE(new_msg); return NT_STATUS_INTERNAL_ERROR; } @@ -290,7 +277,6 @@ static NTSTATUS dns_tombstone_records_zone(TALLOC_CTX *mem_ctx, /* Set DN to the GUID in case the object was moved. */ el = ldb_msg_find_element(new_msg, "objectGUID"); if (el == NULL) { - TALLOC_FREE(old_msg); TALLOC_FREE(new_msg); *error_string = talloc_asprintf(mem_ctx, @@ -302,7 +288,6 @@ static NTSTATUS dns_tombstone_records_zone(TALLOC_CTX *mem_ctx, status = GUID_from_ndr_blob(el->values, &guid); if (!NT_STATUS_IS_OK(status)) { - TALLOC_FREE(old_msg); TALLOC_FREE(new_msg); *error_string = discard_const_p(char, "Error: Invalid GUID.\n"); @@ -318,7 +303,6 @@ static NTSTATUS dns_tombstone_records_zone(TALLOC_CTX *mem_ctx, ret = ldb_modify(samdb, new_msg); if (ret != LDB_SUCCESS) { - TALLOC_FREE(old_msg); TALLOC_FREE(new_msg); *error_string = talloc_asprintf(mem_ctx, @@ -328,7 +312,6 @@ static NTSTATUS dns_tombstone_records_zone(TALLOC_CTX *mem_ctx, ldb_errstring(samdb)); return NT_STATUS_INTERNAL_ERROR; } - TALLOC_FREE(old_msg); TALLOC_FREE(new_msg); } |