From 876217799ed26732be50ef61d978ec9272c9986c Mon Sep 17 00:00:00 2001 From: Anatoliy Atanasov Date: Thu, 24 Jun 2010 20:48:07 +0300 Subject: [PATCH] mem fixes --- source4/auth/session.c | 2 +- source4/dsdb/schema/schema_set.c | 2 ++ source4/lib/ldb/common/ldb_dn.c | 2 +- source4/lib/ldb/common/ldb_msg.c | 31 +++++++++++++++++-------------- 4 files changed, 21 insertions(+), 16 deletions(-) diff --git a/source4/auth/session.c b/source4/auth/session.c index 29ba13e..1be9874 100644 --- a/source4/auth/session.c +++ b/source4/auth/session.c @@ -178,7 +178,7 @@ _PUBLIC_ NTSTATUS auth_generate_session_info(TALLOC_CTX *mem_ctx, group_dn = talloc_asprintf(tmp_ctx, "", group_string); NT_STATUS_HAVE_NO_MEMORY_AND_FREE(group_dn, server_info); - + talloc_free(group_string); group_blob = data_blob_string_const(group_dn); /* This function takes in memberOf values and expands diff --git a/source4/dsdb/schema/schema_set.c b/source4/dsdb/schema/schema_set.c index 07d75c4..269af4d 100644 --- a/source4/dsdb/schema/schema_set.c +++ b/source4/dsdb/schema/schema_set.c @@ -140,6 +140,7 @@ static int dsdb_schema_set_attributes(struct ldb_context *ldb, struct dsdb_schem if (mod_msg->num_elements > 0) { ret = dsdb_replace(ldb, mod_msg, 0); } + talloc_free(mod_msg); } if (ret == LDB_ERR_OPERATIONS_ERROR || ret == LDB_ERR_INSUFFICIENT_ACCESS_RIGHTS || ret == LDB_ERR_INVALID_DN_SYNTAX) { @@ -168,6 +169,7 @@ static int dsdb_schema_set_attributes(struct ldb_context *ldb, struct dsdb_schem if (mod_msg->num_elements > 0) { ret = dsdb_replace(ldb, mod_msg, 0); } + talloc_free(mod_msg); } if (ret == LDB_ERR_OPERATIONS_ERROR || ret == LDB_ERR_INSUFFICIENT_ACCESS_RIGHTS || ret == LDB_ERR_INVALID_DN_SYNTAX) { /* We might be on a read-only DB */ diff --git a/source4/lib/ldb/common/ldb_dn.c b/source4/lib/ldb/common/ldb_dn.c index 00646f6..e1c2d08 100644 --- a/source4/lib/ldb/common/ldb_dn.c +++ b/source4/lib/ldb/common/ldb_dn.c @@ -505,7 +505,7 @@ static bool ldb_dn_explode(struct ldb_dn *dn) * (which is a copy of parse_dn * with spaces trimmed) */ *d++ = '\0'; - dn->components[dn->comp_num].name = talloc_strdup(dn->components, dt); + dn->components[dn->comp_num].name = talloc_strdup(dn, dt); if ( ! dn->components[dn->comp_num].name) { /* ouch */ goto failed; diff --git a/source4/lib/ldb/common/ldb_msg.c b/source4/lib/ldb/common/ldb_msg.c index 4d0149a..483f83d 100644 --- a/source4/lib/ldb/common/ldb_msg.c +++ b/source4/lib/ldb/common/ldb_msg.c @@ -608,7 +608,20 @@ struct ldb_message *ldb_msg_diff(struct ldb_context *ldb, talloc_free(mod); return NULL; } - + + /* look in msg1 to find elements that need to be deleted */ + for (i=0;inum_elements;i++) { + el = ldb_msg_find_element(msg2, msg1->elements[i].name); + if (el == NULL) { + if (ldb_msg_add_empty(mod, + msg1->elements[i].name, + LDB_FLAG_MOD_DELETE, NULL) != LDB_SUCCESS) { + talloc_free(mod); + return NULL; + } + } + } + /* look in msg2 to find elements that need to be added or modified */ for (i=0;inum_elements;i++) { @@ -624,21 +637,11 @@ struct ldb_message *ldb_msg_diff(struct ldb_context *ldb, talloc_free(mod); return NULL; } + talloc_steal(mod->elements, msg2->elements[i].name); + talloc_steal(mod->elements, msg2->elements[i].values); } - /* look in msg1 to find elements that need to be deleted */ - for (i=0;inum_elements;i++) { - el = ldb_msg_find_element(msg2, msg1->elements[i].name); - if (el == NULL) { - if (ldb_msg_add_empty(mod, - msg1->elements[i].name, - LDB_FLAG_MOD_DELETE, NULL) != LDB_SUCCESS) { - talloc_free(mod); - return NULL; - } - } - } - + talloc_free(msg2); return mod; } -- 1.5.5.6