[asterisk-commits] russell: branch 1.4 r291392 - /branches/1.4/channels/chan_sip.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Oct 13 10:23:22 CDT 2010


Author: russell
Date: Wed Oct 13 10:23:19 2010
New Revision: 291392

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=291392
Log:
Lock pvt so pvt->owner can't disappear when queueing up a frame.

This fixes a crash due to a hangup race condition.

ABE-2601

Modified:
    branches/1.4/channels/chan_sip.c

Modified: branches/1.4/channels/chan_sip.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.4/channels/chan_sip.c?view=diff&rev=291392&r1=291391&r2=291392
==============================================================================
--- branches/1.4/channels/chan_sip.c (original)
+++ branches/1.4/channels/chan_sip.c Wed Oct 13 10:23:19 2010
@@ -2214,16 +2214,31 @@
 	if (option_debug)
 		ast_log(LOG_DEBUG, "Auto destroying SIP dialog '%s'\n", p->callid);
 	append_history(p, "AutoDestroy", "%s", p->callid);
+
+	/*
+	 * Lock both the pvt and the channel safely so that we can queue up a frame.
+	 */
+	ast_mutex_lock(&p->lock);
+	while (p->owner && ast_channel_trylock(p->owner)) {
+		DEADLOCK_AVOIDANCE(&p->lock);
+	}
+
 	if (p->owner) {
 		ast_log(LOG_WARNING, "Autodestruct on dialog '%s' with owner in place (Method: %s)\n", p->callid, sip_methods[p->method].text);
 		ast_queue_hangup(p->owner);
+		ast_channel_unlock(p->owner);
+		ast_mutex_unlock(&p->lock);
 	} else if (p->refer && !ast_test_flag(&p->flags[0], SIP_ALREADYGONE)) {
 		if (option_debug > 2)
 			ast_log(LOG_DEBUG, "Finally hanging up channel after transfer: %s\n", p->callid);
 		transmit_request_with_auth(p, SIP_BYE, 0, XMIT_RELIABLE, 1);
 		sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT);
-	} else
+		ast_mutex_unlock(&p->lock);
+	} else {
+		ast_mutex_unlock(&p->lock);
 		sip_destroy(p);
+	}
+
 	return 0;
 }
 




More information about the asterisk-commits mailing list