From 03991ab0734ecbb87a75238d1356fbe0e5b1d38d Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 12 Aug 2008 13:35:15 -0700 Subject: Fix bug 5686 - libsmbclient segfaults with more than one SMBCCTX. Here is a patch to allow many subsystems to be re-initialized. The only functional change I made was to remove the null context tracking, as the memory allocated here is designed to be left for the complete lifetime of the program. Freeing this early (when all smb contexts are destroyed) could crash other users of talloc. Jeremy. (This used to be commit 8c630efd25cf17aff59448ca05c1b44a41964b16) --- source3/libsmb/libsmb_context.c | 38 ++++++++++++++++---------------------- 1 file changed, 16 insertions(+), 22 deletions(-) (limited to 'source3/libsmb') diff --git a/source3/libsmb/libsmb_context.c b/source3/libsmb/libsmb_context.c index a9f0dd16b3..19843383de 100644 --- a/source3/libsmb/libsmb_context.c +++ b/source3/libsmb/libsmb_context.c @@ -30,9 +30,8 @@ /* * Is the logging working / configfile read ? */ -static int SMBC_initialized = 0; - - +static bool SMBC_initialized; +static unsigned int initialized_ctx_count; /* * Get a new empty handle to fill in with your own info @@ -201,22 +200,19 @@ smbc_free_context(SMBCCTX *context, DEBUG(3, ("Context %p successfully freed\n", context)); - gfree_names(); - gfree_loadparm(); - gfree_case_tables(); - gfree_charcnv(); - gfree_interfaces(); - - gencache_shutdown(); - secrets_shutdown(); - - /* release the talloc null_context memory last */ - talloc_disable_null_tracking(); + SAFE_FREE(context->internal); + SAFE_FREE(context); - gfree_debugsyms(); + if (initialized_ctx_count) { + initialized_ctx_count--; + } - SAFE_FREE(context->internal); - SAFE_FREE(context); + if (initialized_ctx_count == 0 && SMBC_initialized) { + gencache_shutdown(); + secrets_shutdown(); + gfree_all(); + SMBC_initialized = false; + } return 0; } @@ -427,9 +423,6 @@ smbc_init_context(SMBCCTX *context) char *user = NULL; char *home = NULL; - /* track talloc null_context memory */ - talloc_enable_null_tracking(); - if (!context) { errno = EBADF; return NULL; @@ -527,7 +520,7 @@ smbc_init_context(SMBCCTX *context) BlockSignals(True, SIGPIPE); /* Done with one-time initialisation */ - SMBC_initialized = 1; + SMBC_initialized = true; TALLOC_FREE(frame); } @@ -616,7 +609,8 @@ smbc_init_context(SMBCCTX *context) */ context->internal->initialized = True; - + initialized_ctx_count++; + return context; } -- cgit