]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
dns scavenging: avoid useless copy of msg
authorDouglas Bagnall <douglas.bagnall@catalyst.net.nz>
Sun, 11 Apr 2021 01:45:19 +0000 (13:45 +1200)
committerAndrew Bartlett <abartlet@samba.org>
Sun, 20 Jun 2021 23:26:32 +0000 (23:26 +0000)
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 6084808ca34c810b6481f1477c54bc90b2c24b5b..db341364902a72419feb84961d687451302cf400 100644 (file)
@@ -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);
        }