[asterisk-commits] russell: branch 1.4 r104086 - /branches/1.4/channels/chan_agent.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Feb 25 12:38:11 CST 2008


Author: russell
Date: Mon Feb 25 12:38:10 2008
New Revision: 104086

URL: http://svn.digium.com/view/asterisk?view=rev&rev=104086
Log:
Ensure that the channel doesn't disappear in agent_logoff().  If it does, it
could cause a crash.
(fixes the crash reported in BE-396)

Modified:
    branches/1.4/channels/chan_agent.c

Modified: branches/1.4/channels/chan_agent.c
URL: http://svn.digium.com/view/asterisk/branches/1.4/channels/chan_agent.c?view=diff&rev=104086&r1=104085&r2=104086
==============================================================================
--- branches/1.4/channels/chan_agent.c (original)
+++ branches/1.4/channels/chan_agent.c Mon Feb 25 12:38:10 2008
@@ -1581,10 +1581,29 @@
 			ret = 0;
 			if (p->owner || p->chan) {
 				if (!soft) {
-					if (p->owner)
+					ast_mutex_lock(&p->lock);
+
+					while (p->owner && ast_channel_trylock(p->owner)) {
+						ast_mutex_unlock(&p->lock);
+						usleep(1);
+						ast_mutex_lock(&p->lock);
+					}
+					if (p->owner) {
 						ast_softhangup(p->owner, AST_SOFTHANGUP_EXPLICIT);
-					if (p->chan)
+						ast_channel_unlock(p->owner);
+					}
+
+					while (p->chan && ast_channel_trylock(p->chan)) {
+						ast_mutex_unlock(&p->lock);
+						usleep(1);
+						ast_mutex_lock(&p->lock);
+					}
+					if (p->chan) {
 						ast_softhangup(p->chan, AST_SOFTHANGUP_EXPLICIT);
+						ast_channel_unlock(p->chan);
+					}
+
+					ast_mutex_unlock(&p->lock);
 				} else
 					p->deferlogoff = 1;
 			} else {




More information about the asterisk-commits mailing list