[svn-commits] kmoore: branch group/media_formats-reviewed-trunk r418779 - /team/group/media...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Wed Jul 16 10:52:00 CDT 2014


Author: kmoore
Date: Wed Jul 16 10:51:52 2014
New Revision: 418779

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=418779
Log:
media formats: Ensure that chan_sip unloads cleanly

This tweaks chan_sip to clean up after itself properly. Its
unload_module() call is now also used as cleanup in case of module
load declination or failure.

Review: https://reviewboard.asterisk.org/r/3805/

Modified:
    team/group/media_formats-reviewed-trunk/channels/chan_sip.c

Modified: team/group/media_formats-reviewed-trunk/channels/chan_sip.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats-reviewed-trunk/channels/chan_sip.c?view=diff&rev=418779&r1=418778&r2=418779
==============================================================================
--- team/group/media_formats-reviewed-trunk/channels/chan_sip.c (original)
+++ team/group/media_formats-reviewed-trunk/channels/chan_sip.c Wed Jul 16 10:51:52 2014
@@ -1763,7 +1763,7 @@
 {
 	int i;
 	for (i = 0; i < ARRAY_LEN(event_state_compositors); i++) {
-		ao2_ref(event_state_compositors[i].compositor, -1);
+		ao2_cleanup(event_state_compositors[i].compositor);
 	}
 }
 
@@ -34223,6 +34223,8 @@
 	.sipinfo_send = sipinfo_send,
 };
 
+static int unload_module(void);
+
 /*!
  * \brief Load the module
  *
@@ -34238,14 +34240,17 @@
 	ast_verbose("SIP channel loading...\n");
 
 	if (STASIS_MESSAGE_TYPE_INIT(session_timeout_type)) {
+		unload_module();
 		return AST_MODULE_LOAD_FAILURE;
 	}
 
 	if (!(sip_tech.capabilities = ast_format_cap_alloc(0))) {
+		unload_module();
 		return AST_MODULE_LOAD_FAILURE;
 	}
 
 	if (ast_sip_api_provider_register(&chan_sip_api_provider)) {
+		unload_module();
 		return AST_MODULE_LOAD_FAILURE;
 	}
 
@@ -34260,10 +34265,12 @@
 	if (!peers || !peers_by_ip || !dialogs || !dialogs_needdestroy || !dialogs_rtpcheck
 		|| !threadt) {
 		ast_log(LOG_ERROR, "Unable to create primary SIP container(s)\n");
+		unload_module();
 		return AST_MODULE_LOAD_FAILURE;
 	}
 
 	if (!(sip_cfg.caps = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT))) {
+		unload_module();
 		return AST_MODULE_LOAD_FAILURE;
 	}
 	ast_format_cap_append_by_type(sip_tech.capabilities, AST_MEDIA_TYPE_AUDIO);
@@ -34273,11 +34280,13 @@
 
 	if (!(sched = ast_sched_context_create())) {
 		ast_log(LOG_ERROR, "Unable to create scheduler context\n");
+		unload_module();
 		return AST_MODULE_LOAD_FAILURE;
 	}
 
 	if (!(io = io_context_create())) {
 		ast_log(LOG_ERROR, "Unable to create I/O context\n");
+		unload_module();
 		return AST_MODULE_LOAD_FAILURE;
 	}
 
@@ -34285,15 +34294,14 @@
 
 	can_parse_xml = sip_is_xml_parsable();
 	if (reload_config(sip_reloadreason)) {	/* Load the configuration from sip.conf */
-		ast_sip_api_provider_unregister();
+		unload_module();
 		return AST_MODULE_LOAD_DECLINE;
 	}
 
 	/* Initialize bogus peer. Can be done first after reload_config() */
 	if (!(bogus_peer = temp_peer("(bogus_peer)"))) {
 		ast_log(LOG_ERROR, "Unable to create bogus_peer for authentication\n");
-		io_context_destroy(io);
-		ast_sched_context_destroy(sched);
+		unload_module();
 		return AST_MODULE_LOAD_FAILURE;
 	}
 	/* Make sure the auth will always fail. */
@@ -34308,16 +34316,14 @@
 	memset((void *) &sip_tech_info.send_digit_begin, 0, sizeof(sip_tech_info.send_digit_begin));
 
 	if (ast_msg_tech_register(&sip_msg_tech)) {
-		/* LOAD_FAILURE stops Asterisk, so cleanup is a moot point. */
+		unload_module();
 		return AST_MODULE_LOAD_FAILURE;
 	}
 
 	/* Make sure we can register our sip channel type */
 	if (ast_channel_register(&sip_tech)) {
 		ast_log(LOG_ERROR, "Unable to register channel type 'SIP'\n");
-		ao2_t_ref(bogus_peer, -1, "unref the bogus_peer");
-		io_context_destroy(io);
-		ast_sched_context_destroy(sched);
+		unload_module();
 		return AST_MODULE_LOAD_FAILURE;
 	}
 
@@ -34364,13 +34370,13 @@
 	initialize_escs();
 
 	if (sip_epa_register(&cc_epa_static_data)) {
-		ast_sip_api_provider_unregister();
+		unload_module();
 		return AST_MODULE_LOAD_DECLINE;
 	}
 
 	if (sip_reqresp_parser_init() == -1) {
 		ast_log(LOG_ERROR, "Unable to initialize the SIP request and response parser\n");
-		ast_sip_api_provider_unregister();
+		unload_module();
 		return AST_MODULE_LOAD_DECLINE;
 	}
 
@@ -34379,16 +34385,16 @@
 		 * in incoming PUBLISH requests
 		 */
 		if (ast_cc_agent_register(&sip_cc_agent_callbacks)) {
-			ast_sip_api_provider_unregister();
+			unload_module();
 			return AST_MODULE_LOAD_DECLINE;
 		}
 	}
 	if (ast_cc_monitor_register(&sip_cc_monitor_callbacks)) {
-		ast_sip_api_provider_unregister();
+		unload_module();
 		return AST_MODULE_LOAD_DECLINE;
 	}
 	if (!(sip_monitor_instances = ao2_container_alloc(37, sip_monitor_instance_hash_fn, sip_monitor_instance_cmp_fn))) {
-		ast_sip_api_provider_unregister();
+		unload_module();
 		return AST_MODULE_LOAD_DECLINE;
 	}
 
@@ -34529,7 +34535,7 @@
 
 	ast_mutex_lock(&authl_lock);
 	if (authl) {
-		ao2_t_ref(authl, -1, "Removing global authentication");
+		ao2_t_cleanup(authl, "Removing global authentication");
 		authl = NULL;
 	}
 	ast_mutex_unlock(&authl_lock);
@@ -34574,15 +34580,15 @@
 		ast_debug(2, "TCP/TLS thread container did not become empty :(\n");
 	}
 
-	ao2_t_ref(bogus_peer, -1, "unref the bogus_peer");
-
-	ao2_t_ref(peers, -1, "unref the peers table");
-	ao2_t_ref(peers_by_ip, -1, "unref the peers_by_ip table");
-	ao2_t_ref(dialogs, -1, "unref the dialogs table");
-	ao2_t_ref(dialogs_needdestroy, -1, "unref dialogs_needdestroy");
-	ao2_t_ref(dialogs_rtpcheck, -1, "unref dialogs_rtpcheck");
-	ao2_t_ref(threadt, -1, "unref the thread table");
-	ao2_t_ref(sip_monitor_instances, -1, "unref the sip_monitor_instances table");
+	ao2_t_cleanup(bogus_peer, "unref the bogus_peer");
+
+	ao2_t_cleanup(peers, "unref the peers table");
+	ao2_t_cleanup(peers_by_ip, "unref the peers_by_ip table");
+	ao2_t_cleanup(dialogs, "unref the dialogs table");
+	ao2_t_cleanup(dialogs_needdestroy, "unref dialogs_needdestroy");
+	ao2_t_cleanup(dialogs_rtpcheck, "unref dialogs_rtpcheck");
+	ao2_t_cleanup(threadt, "unref the thread table");
+	ao2_t_cleanup(sip_monitor_instances, "unref the sip_monitor_instances table");
 
 	clear_sip_domains();
 	sip_cfg.contact_acl = ast_free_acl_list(sip_cfg.contact_acl);
@@ -34610,9 +34616,9 @@
 		notify_types = NULL;
 	}
 
-	ao2_ref(sip_tech.capabilities, -1);
+	ao2_cleanup(sip_tech.capabilities);
 	sip_tech.capabilities = NULL;
-	ao2_ref(sip_cfg.caps, -1);
+	ao2_cleanup(sip_cfg.caps);
 	sip_cfg.caps = NULL;
 
 	STASIS_MESSAGE_TYPE_CLEANUP(session_timeout_type);




More information about the svn-commits mailing list