ensure that unload_dynamic_module won't continue dereferencing a module pointer after...
authorKevin P. Fleming <kpfleming@digium.com>
Sat, 26 Aug 2006 19:45:16 +0000 (19:45 +0000)
committerKevin P. Fleming <kpfleming@digium.com>
Sat, 26 Aug 2006 19:45:16 +0000 (19:45 +0000)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@41196 65c4cc65-6c06-0410-ace0-fbb531ad65f3

main/loader.c

index 4ece4ae..30f5aa6 100644 (file)
@@ -323,9 +323,14 @@ static struct ast_module *find_resource(const char *resource, int do_lock)
 #if LOADABLE_MODULES
 static void unload_dynamic_module(struct ast_module *mod)
 {
 #if LOADABLE_MODULES
 static void unload_dynamic_module(struct ast_module *mod)
 {
-       if (mod->lib)
-               while (!dlclose(mod->lib));
-       /* WARNING: the structure pointed to by mod is now gone! */
+       void *lib = mod->lib;
+
+       /* WARNING: the structure pointed to by mod is going to
+          disappear when this operation succeeds, so we can't
+          dereference it */
+
+       if (lib)
+               while (!dlclose(lib));
 }
 
 static struct ast_module *load_dynamic_module(const char *resource_in, unsigned int global_symbols_only)
 }
 
 static struct ast_module *load_dynamic_module(const char *resource_in, unsigned int global_symbols_only)