fix some issues with crashing on unload, when it didn't completely load cleanly
authorRussell Bryant <russell@russellbryant.com>
Fri, 2 Nov 2007 22:36:30 +0000 (22:36 +0000)
committerRussell Bryant <russell@russellbryant.com>
Fri, 2 Nov 2007 22:36:30 +0000 (22:36 +0000)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@88409 65c4cc65-6c06-0410-ace0-fbb531ad65f3

channels/chan_unistim.c

index 793750e..7efd289 100644 (file)
@@ -5619,10 +5619,13 @@ chanreg_failed:
        /*! XXX \todo Leaking anything allocated by reload_config() ... */
 reload_failed:
        sched_context_destroy(sched);
+       sched = NULL;
 sched_failed:
        io_context_destroy(io);
+       io = NULL;
 io_failed:
        free(buff);
+       buff = NULL;
 buff_failed:
        return AST_MODULE_LOAD_DECLINE;
 }
@@ -5630,7 +5633,8 @@ buff_failed:
 static int unload_module(void)
 {
        /* First, take us out of the channel loop */
-       sched_context_destroy(sched);
+       if (sched)
+               sched_context_destroy(sched);
 
        ast_cli_unregister_multiple(unistim_cli, ARRAY_LEN(unistim_cli));
 
@@ -5646,8 +5650,10 @@ static int unload_module(void)
        monitor_thread = AST_PTHREADT_STOP;
        ast_mutex_unlock(&monlock);
 
-       free(buff);
-       close(unistimsock);
+       if (buff)
+               free(buff);
+       if (unistimsock > -1)
+               close(unistimsock);
 
        return 0;
 }