From 9481764b1985219e4cedfaab2620e15a074b2dd1 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Fri, 4 Aug 2006 12:05:46 +0000 Subject: 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) --- source4/lib/ldb/common/ldb_modules.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'source4/lib/ldb/common') 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) { -- cgit