summaryrefslogtreecommitdiff
path: root/source4
diff options
context:
space:
mode:
authorSimo Sorce <idra@samba.org>2006-08-04 12:05:46 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 14:15:22 -0500
commit9481764b1985219e4cedfaab2620e15a074b2dd1 (patch)
treed5f4d16a146dcecef08a8ea5d105d21394d695fd /source4
parentbf5e85ba2502ccc8bd94eb216a82d1497ca7ff19 (diff)
downloadsamba-9481764b1985219e4cedfaab2620e15a074b2dd1.tar.gz
samba-9481764b1985219e4cedfaab2620e15a074b2dd1.tar.bz2
samba-9481764b1985219e4cedfaab2620e15a074b2dd1.zip
r17398: avoid a memleak when we are returned 0 results and make a more creative use of memory contexts
(This used to be commit fc97b5dc8ce65232a7a98ffb59def44a931b1565)
Diffstat (limited to 'source4')
-rw-r--r--source4/lib/ldb/common/ldb_modules.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/source4/lib/ldb/common/ldb_modules.c b/source4/lib/ldb/common/ldb_modules.c
index 7d1a91126e..b425796dfc 100644
--- a/source4/lib/ldb/common/ldb_modules.c
+++ b/source4/lib/ldb/common/ldb_modules.c
@@ -261,17 +261,17 @@ int ldb_load_modules(struct ldb_context *ldb, const char *options[])
if ((modules == NULL) && (strcmp("ldap", ldb->modules->ops->name) != 0)) {
int ret;
const char * const attrs[] = { "@LIST" , NULL};
- struct ldb_result *res;
- struct ldb_dn *mods;
+ struct ldb_result *res = NULL;
+ struct ldb_dn *mods_dn;
- mods = ldb_dn_explode(mem_ctx, "@MODULES");
- if (mods == NULL) {
+ mods_dn = ldb_dn_explode(mem_ctx, "@MODULES");
+ if (mods_dn == NULL) {
talloc_free(mem_ctx);
return -1;
}
- ret = ldb_search(ldb, mods, LDB_SCOPE_BASE, "", attrs, &res);
- talloc_free(mods);
+ ret = ldb_search(ldb, mods_dn, LDB_SCOPE_BASE, "", attrs, &res);
+ if (res) talloc_steal(mods_dn, res);
if (ret == LDB_SUCCESS && (res->count == 0 || res->msgs[0]->num_elements == 0)) {
ldb_debug(ldb, LDB_DEBUG_TRACE, "no modules required by the db\n");
} else {
@@ -282,7 +282,6 @@ int ldb_load_modules(struct ldb_context *ldb, const char *options[])
}
if (res->count > 1) {
ldb_debug(ldb, LDB_DEBUG_FATAL, "Too many records found (%d), bailing out\n", res->count);
- talloc_free(res);
talloc_free(mem_ctx);
return -1;
}
@@ -290,8 +289,9 @@ int ldb_load_modules(struct ldb_context *ldb, const char *options[])
modules = ldb_modules_list_from_string(ldb, mem_ctx,
(const char *)res->msgs[0]->elements[0].values[0].data);
- talloc_free(res);
}
+
+ talloc_free(mods_dn);
}
if (modules != NULL) {