[svn-commits] russell: branch group/chan_unistim r88324 - /team/group/chan_unistim/channels/

SVN commits to the Digium repositories svn-commits at lists.digium.com
Fri Nov 2 14:48:35 CDT 2007


Author: russell
Date: Fri Nov  2 14:48:34 2007
New Revision: 88324

URL: http://svn.digium.com/view/asterisk?view=rev&rev=88324
Log:
restructure load_module to better clean up after a failure

Modified:
    team/group/chan_unistim/channels/chan_unistim.c

Modified: team/group/chan_unistim/channels/chan_unistim.c
URL: http://svn.digium.com/view/asterisk/team/group/chan_unistim/channels/chan_unistim.c?view=diff&rev=88324&r1=88323&r2=88324
==============================================================================
--- team/group/chan_unistim/channels/chan_unistim.c (original)
+++ team/group/chan_unistim/channels/chan_unistim.c Fri Nov  2 14:48:34 2007
@@ -5516,45 +5516,51 @@
 	int res;
 
 	if (!(buff = ast_malloc(SIZE_PAGE)))
-		return AST_MODULE_LOAD_DECLINE;
+		goto buff_failed;
 
 	io = io_context_create();
 	if (!io) {
-		ast_log(LOG_WARNING, "Unable to create I/O context\n");
-		free(buff);
-		return AST_MODULE_LOAD_DECLINE;
+		ast_log(LOG_ERROR, "Failed to allocate IO context\n");
+		goto io_failed;
 	}
 
 	sched = sched_context_create();
 	if (!sched) {
-		ast_log(LOG_WARNING, "Unable to create schedule context\n");
-		free(buff);
-		return AST_MODULE_LOAD_DECLINE;
+		ast_log(LOG_ERROR, "Failed to allocate scheduler context\n");
+		goto sched_failed;
 	}
 
 	res = reload_config();
-	if (res) {
-		free(buff);
-		return AST_MODULE_LOAD_DECLINE;
-	}
+	if (res)
+		goto reload_failed;
 
 	/* Make sure we can register our unistim channel type */
 	if (ast_channel_register(&unistim_tech)) {
-		ast_log(LOG_ERROR, "Unable to register channel class %s\n", type);
-		unload_module();
-		free(buff);
-		return AST_MODULE_LOAD_FAILURE;
+		ast_log(LOG_ERROR, "Unable to register channel type '%s'\n", type);
+		goto chanreg_failed;
 	} 
 
 	ast_rtp_proto_register(&unistim_rtp);
+
 	ast_cli_register_multiple(unistim_cli, ARRAY_LEN(unistim_cli));
 
 	restart_monitor();
 
 	return AST_MODULE_LOAD_SUCCESS;
-}
-
-static int __unload_module(void)
+
+chanreg_failed:
+	/*! XXX \todo Leaking anything allocated by reload_config() ... */
+reload_failed:
+	sched_context_destroy(sched);
+sched_failed:
+	io_context_destroy(io);
+io_failed:
+	free(buff);
+buff_failed:
+	return AST_MODULE_LOAD_DECLINE;
+}
+
+static int unload_module(void)
 {
 	/* First, take us out of the channel loop */
 	sched_context_destroy(sched);
@@ -5564,21 +5570,15 @@
 	ast_channel_unregister(&unistim_tech);
 	ast_rtp_proto_unregister(&unistim_rtp);
 
-	/* Hangup all device with active sessions, delete lines then devices ?*/
-	if (!ast_mutex_lock(&monlock)) {
-		if (monitor_thread && (monitor_thread != AST_PTHREADT_STOP) && (monitor_thread != AST_PTHREADT_NULL)) {
-			pthread_cancel(monitor_thread);
-			pthread_kill(monitor_thread, SIGURG);
-			pthread_join(monitor_thread, NULL);
-		}
-		monitor_thread = AST_PTHREADT_STOP;
-		ast_mutex_unlock(&monlock);
-	} else {
-		ast_log(LOG_WARNING, "Unable to lock the monitor\n");
-		return -1;
-	}
-
-	/* free global buffer and close socket */
+	ast_mutex_lock(&monlock);
+	if (monitor_thread && (monitor_thread != AST_PTHREADT_STOP) && (monitor_thread != AST_PTHREADT_NULL)) {
+		pthread_cancel(monitor_thread);
+		pthread_kill(monitor_thread, SIGURG);
+		pthread_join(monitor_thread, NULL);
+	}
+	monitor_thread = AST_PTHREADT_STOP;
+	ast_mutex_unlock(&monlock);
+
 	free(buff);
 	close(unistimsock);
 
@@ -5590,12 +5590,6 @@
 {
 	unistim_reload(0, 0, NULL);
 	return 0;
-}
-
-
-static int unload_module(void)
-{
-	return __unload_module();
 }
 
 AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "UNISTIM Protocol (USTM)",




More information about the svn-commits mailing list