[asterisk-commits] mmichelson: branch 1.6.0 r114065 - in /branches/1.6.0: ./ main/features.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Apr 11 10:51:10 CDT 2008


Author: mmichelson
Date: Fri Apr 11 10:51:10 2008
New Revision: 114065

URL: http://svn.digium.com/view/asterisk?view=rev&rev=114065
Log:
Merged revisions 114064 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/trunk

................
r114064 | mmichelson | 2008-04-11 10:49:35 -0500 (Fri, 11 Apr 2008) | 19 lines

Merged revisions 114063 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.4

........
r114063 | mmichelson | 2008-04-11 10:44:28 -0500 (Fri, 11 Apr 2008) | 11 lines

Fix a race condition that may happen between a sip hangup
and a "core show channel" command. This patch adds locking
to prevent the resulting crash.

(closes issue #12155)
Reported by: tsearle
Patches:
      show_channels_crash2.patch uploaded by tsearle (license 373)
Tested by: tsearle


........

................

Modified:
    branches/1.6.0/   (props changed)
    branches/1.6.0/main/features.c

Propchange: branches/1.6.0/
------------------------------------------------------------------------------
Binary property 'trunk-merged' - no diff available.

Modified: branches/1.6.0/main/features.c
URL: http://svn.digium.com/view/asterisk/branches/1.6.0/main/features.c?view=diff&rev=114065&r1=114064&r2=114065
==============================================================================
--- branches/1.6.0/main/features.c (original)
+++ branches/1.6.0/main/features.c Fri Apr 11 10:51:10 2008
@@ -2118,6 +2118,7 @@
 	bridge_cdr = ast_cdr_alloc();
 	if (bridge_cdr) {
 		if (chan->cdr && peer->cdr) { /* both of them? merge */
+			ast_channel_lock(chan); /* lock the channel before modifying cdrs */
 			ast_cdr_init(bridge_cdr,chan); /* seems more logicaller to use the  destination as a base, but, really, it's random */
 			ast_cdr_start(bridge_cdr); /* now is the time to start */
 			
@@ -2126,14 +2127,22 @@
 			if (!ast_test_flag(chan->cdr, AST_CDR_FLAG_LOCKED))
 				ast_cdr_discard(chan->cdr); /* if locked cdrs are in chan, they are taken over in the merge */
 			
+			chan->cdr = NULL;
+			ast_channel_unlock(chan);
 			/* absorb the peer cdr */
+			ast_channel_lock(peer);
 			ast_cdr_merge(bridge_cdr, peer->cdr);
 			if (!ast_test_flag(peer->cdr, AST_CDR_FLAG_LOCKED))
 				ast_cdr_discard(peer->cdr); /* if locked cdrs are in peer, they are taken over in the merge */
 			
-			peer->cdr = NULL;
+			peer->cdr = NULL; /* remove pointer to freed memory before releasing the lock */
+			ast_channel_unlock(peer);
+
+			ast_channel_lock(chan);
 			chan->cdr = bridge_cdr; /* make this available to the rest of the world via the chan while the call is in progress */
+			ast_channel_unlock(chan);
 		} else if (chan->cdr) {
+			ast_channel_lock(chan); /* Lock before modifying CDR */
 			/* take the cdr from the channel - literally */
 			ast_cdr_init(bridge_cdr,chan);
 			/* absorb this data */
@@ -2141,7 +2150,9 @@
 			if (!ast_test_flag(chan->cdr, AST_CDR_FLAG_LOCKED))
 				ast_cdr_discard(chan->cdr); /* if locked cdrs are in chan, they are taken over in the merge */
 			chan->cdr = bridge_cdr; /* make this available to the rest of the world via the chan while the call is in progress */
+			ast_channel_unlock(chan);
 		} else if (peer->cdr) {
+			ast_channel_lock(peer); /* Lock before modifying CDR */
 			/* take the cdr from the peer - literally */
 			ast_cdr_init(bridge_cdr,peer);
 			/* absorb this data */
@@ -2150,10 +2161,13 @@
 				ast_cdr_discard(peer->cdr); /* if locked cdrs are in chan, they are taken over in the merge */
 			peer->cdr = NULL;
 			peer->cdr = bridge_cdr; /* make this available to the rest of the world via the chan while the call is in progress */
+			ast_channel_unlock(peer);
 		} else {
+			ast_channel_lock(chan); /* Lock before modifying CDR */
 			/* make up a new cdr */
 			ast_cdr_init(bridge_cdr,chan); /* eh, just pick one of them */
 			chan->cdr = bridge_cdr; /*  */
+			ast_channel_unlock(chan);
 		}
 		if (ast_strlen_zero(bridge_cdr->dstchannel)) {
 			if (strcmp(bridge_cdr->channel, peer->name) != 0)




More information about the asterisk-commits mailing list