From 7cbcf652c51d283ac55b898c60ea39e45a48e5dd Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 2 May 2010 15:53:14 +0200 Subject: [PATCH] s4-ldb: use a parent context in the ldb utils This avoids a talloc free with references error on exit --- source4/lib/ldb/tools/ldbadd.c | 5 +++-- source4/lib/ldb/tools/ldbdel.c | 5 +++-- source4/lib/ldb/tools/ldbedit.c | 6 ++++-- source4/lib/ldb/tools/ldbmodify.c | 5 +++-- source4/lib/ldb/tools/ldbrename.c | 5 +++-- source4/lib/ldb/tools/ldbsearch.c | 6 ++++-- 6 files changed, 20 insertions(+), 12 deletions(-) diff --git a/source4/lib/ldb/tools/ldbadd.c b/source4/lib/ldb/tools/ldbadd.c index 0dd35cc1b3..e057b873a8 100644 --- a/source4/lib/ldb/tools/ldbadd.c +++ b/source4/lib/ldb/tools/ldbadd.c @@ -95,8 +95,9 @@ int main(int argc, const char **argv) struct ldb_context *ldb; unsigned int i, count = 0; int ret=0; + TALLOC_CTX *mem_ctx = talloc_new(NULL); - ldb = ldb_init(NULL, NULL); + ldb = ldb_init(mem_ctx, NULL); options = ldb_cmdline_process(ldb, argc, argv, usage); @@ -130,7 +131,7 @@ int main(int argc, const char **argv) ldb_transaction_cancel(ldb); } - talloc_free(ldb); + talloc_free(mem_ctx); printf("Added %d records with %d failures\n", count, failures); diff --git a/source4/lib/ldb/tools/ldbdel.c b/source4/lib/ldb/tools/ldbdel.c index 04884e1bec..6994b3ddb6 100644 --- a/source4/lib/ldb/tools/ldbdel.c +++ b/source4/lib/ldb/tools/ldbdel.c @@ -87,8 +87,9 @@ int main(int argc, const char **argv) struct ldb_cmdline *options; struct ldb_context *ldb; int ret = 0, i; + TALLOC_CTX *mem_ctx = talloc_new(NULL); - ldb = ldb_init(NULL, NULL); + ldb = ldb_init(mem_ctx, NULL); options = ldb_cmdline_process(ldb, argc, argv, usage); @@ -127,7 +128,7 @@ int main(int argc, const char **argv) } } - talloc_free(ldb); + talloc_free(mem_ctx); return ret; } diff --git a/source4/lib/ldb/tools/ldbedit.c b/source4/lib/ldb/tools/ldbedit.c index 4c5683cd83..1866cc373e 100644 --- a/source4/lib/ldb/tools/ldbedit.c +++ b/source4/lib/ldb/tools/ldbedit.c @@ -284,8 +284,9 @@ int main(int argc, const char **argv) int ret; const char *expression = "(|(objectClass=*)(distinguishedName=*))"; const char * const * attrs = NULL; + TALLOC_CTX *mem_ctx = talloc_new(NULL); - ldb = ldb_init(NULL, NULL); + ldb = ldb_init(mem_ctx, NULL); options = ldb_cmdline_process(ldb, argc, argv, usage); @@ -330,6 +331,7 @@ int main(int argc, const char **argv) } } - talloc_free(ldb); + talloc_free(mem_ctx); + return 0; } diff --git a/source4/lib/ldb/tools/ldbmodify.c b/source4/lib/ldb/tools/ldbmodify.c index 57988cbb30..ecbdadfd65 100644 --- a/source4/lib/ldb/tools/ldbmodify.c +++ b/source4/lib/ldb/tools/ldbmodify.c @@ -94,8 +94,9 @@ int main(int argc, const char **argv) struct ldb_context *ldb; int count=0; int i, ret=LDB_SUCCESS; + TALLOC_CTX *mem_ctx = talloc_new(NULL); - ldb = ldb_init(NULL, NULL); + ldb = ldb_init(mem_ctx, NULL); options = ldb_cmdline_process(ldb, argc, argv, usage); @@ -115,7 +116,7 @@ int main(int argc, const char **argv) } } - talloc_free(ldb); + talloc_free(mem_ctx); printf("Modified %d records with %d failures\n", count, failures); diff --git a/source4/lib/ldb/tools/ldbrename.c b/source4/lib/ldb/tools/ldbrename.c index bfccacc206..e0f258ce85 100644 --- a/source4/lib/ldb/tools/ldbrename.c +++ b/source4/lib/ldb/tools/ldbrename.c @@ -51,8 +51,9 @@ int main(int argc, const char **argv) int ret; struct ldb_cmdline *options; struct ldb_dn *dn1, *dn2; + TALLOC_CTX *mem_ctx = talloc_new(NULL); - ldb = ldb_init(NULL, NULL); + ldb = ldb_init(mem_ctx, NULL); options = ldb_cmdline_process(ldb, argc, argv, usage); @@ -71,7 +72,7 @@ int main(int argc, const char **argv) options->argv[0], options->argv[1], ldb_errstring(ldb)); } - talloc_free(ldb); + talloc_free(mem_ctx); return ret; } diff --git a/source4/lib/ldb/tools/ldbsearch.c b/source4/lib/ldb/tools/ldbsearch.c index 327a75ed8d..179646c73f 100644 --- a/source4/lib/ldb/tools/ldbsearch.c +++ b/source4/lib/ldb/tools/ldbsearch.c @@ -271,8 +271,9 @@ int main(int argc, const char **argv) struct ldb_cmdline *options; int ret = -1; const char *expression = "(|(objectClass=*)(distinguishedName=*))"; + TALLOC_CTX *mem_ctx = talloc_new(NULL); - ldb = ldb_init(NULL, NULL); + ldb = ldb_init(mem_ctx, NULL); if (ldb == NULL) { return -1; } @@ -311,6 +312,7 @@ int main(int argc, const char **argv) ret = do_search(ldb, basedn, options, expression, attrs); } - talloc_free(ldb); + talloc_free(mem_ctx); + return ret; } -- 2.34.1