@echo Linking testwrite
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBSMBCLIENT) -lpopt
+testctx: testctx.o
+ @echo Linking testctx
+ $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBSMBCLIENT) -lpopt
+
smbsh:
make -C smbwrapper
--- /dev/null
+#include <libsmbclient.h>
+
+void create_and_destroy_context (void)
+{
+ SMBCCTX *ctx;
+ ctx = smbc_new_context ();
+ smbc_init_context (ctx);
+
+ smbc_free_context (ctx, 1);
+}
+
+int main (int argc, char **argv)
+{
+ create_and_destroy_context ();
+ create_and_destroy_context ();
+ return 0;
+}
static smb_iconv_t conv_handles[NUM_CHARSETS][NUM_CHARSETS];
static bool conv_silent; /* Should we do a debug if the conversion fails ? */
+static bool initialized;
/**
* Return the name of a charset to give to iconv().
void lazy_initialize_conv(void)
{
- static int initialized = False;
-
if (!initialized) {
- initialized = True;
load_case_tables();
init_iconv();
+ initialized = true;
}
}
}
}
}
+ initialized = false;
}
/**
/*
* This is to allow assignment to DEBUGLEVEL before the debug
- * system has been initialised.
+ * system has been initialized.
*/
static int debug_all_class_hack = 1;
static bool debug_all_class_isset_hack = True;
Free memory pointed to by global pointers.
****************************************************************************/
+static bool initialized;
+
void gfree_debugsyms(void)
{
int i;
SAFE_FREE( classname_table );
}
- if ( DEBUGLEVEL_CLASS != &debug_all_class_hack )
+ if ( DEBUGLEVEL_CLASS != &debug_all_class_hack ) {
SAFE_FREE( DEBUGLEVEL_CLASS );
+ DEBUGLEVEL_CLASS = &debug_all_class_hack;
+ }
- if ( DEBUGLEVEL_CLASS_ISSET != &debug_all_class_isset_hack )
+ if ( DEBUGLEVEL_CLASS_ISSET != &debug_all_class_isset_hack ) {
SAFE_FREE( DEBUGLEVEL_CLASS_ISSET );
+ DEBUGLEVEL_CLASS_ISSET = &debug_all_class_isset_hack;
+ }
SAFE_FREE(format_bufr);
+
+ debug_num_classes = 0;
+
+ debug_level = DEBUGLEVEL_CLASS;
+
+ initialized = false;
}
/****************************************************************************
void debug_init(void)
{
- static bool initialised = False;
const char **p;
- if (initialised)
+ if (initialized)
return;
- initialised = True;
+ initialized = true;
for(p = default_classname_table; *p; p++) {
debug_add_class(*p);
gfree_names();
gfree_loadparm();
gfree_case_tables();
- gfree_debugsyms();
gfree_charcnv();
gfree_interfaces();
-
- /* release the talloc null_context memory last */
- talloc_disable_null_tracking();
+ gfree_debugsyms();
}
const char *my_netbios_names(int i)
static bool upcase_table_use_unmap;
static bool lowcase_table_use_unmap;
static bool valid_table_use_unmap;
+static bool initialized;
/**
* Destroy global objects allocated by load_case_tables()
else
SAFE_FREE(valid_table);
}
+ initialized = false;
}
/**
void load_case_tables(void)
{
- static int initialised;
char *old_locale = NULL, *saved_locale = NULL;
int i;
TALLOC_CTX *frame = NULL;
- if (initialised) {
+ if (initialized) {
return;
}
- initialised = 1;
+ initialized = true;
frame = talloc_stackframe();
/*
* 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
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;
}
char *user = NULL;
char *home = NULL;
- /* track talloc null_context memory */
- talloc_enable_null_tracking();
-
if (!context) {
errno = EBADF;
return NULL;
BlockSignals(True, SIGPIPE);
/* Done with one-time initialisation */
- SMBC_initialized = 1;
+ SMBC_initialized = true;
TALLOC_FREE(frame);
}
*/
context->internal->initialized = True;
-
+ initialized_ctx_count++;
+
return context;
}
SAFE_FREE( f );
f = next;
}
+ file_lists = NULL;
/* Free resources allocated to services */