summaryrefslogtreecommitdiff
path: root/source3/libsmb
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2008-08-12 13:35:15 -0700
committerJeremy Allison <jra@samba.org>2008-08-12 13:35:15 -0700
commit03991ab0734ecbb87a75238d1356fbe0e5b1d38d (patch)
treec96c68c0f2fd8359c2250621f4b0938903ae385f /source3/libsmb
parent9caabc441b3bfe860f9719cf64b6646f58a5cb59 (diff)
downloadsamba-03991ab0734ecbb87a75238d1356fbe0e5b1d38d.tar.gz
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)
Diffstat (limited to 'source3/libsmb')
-rw-r--r--source3/libsmb/libsmb_context.c38
1 files changed, 16 insertions, 22 deletions
diff --git a/source3/libsmb/libsmb_context.c b/source3/libsmb/libsmb_context.c
index a9f0dd16b3b..19843383de2 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;
}