[asterisk-commits] jrose: trunk r367419 - /trunk/main/pbx.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed May 23 15:39:26 CDT 2012


Author: jrose
Date: Wed May 23 15:39:22 2012
New Revision: 367419

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=367419
Log:
logger: Fix a potential callid reference leak discovered in development

Uncovered a nasty reference leak while I was writing some changes to
chan_dahdi/sig_analog. Slapped myself around a bit after seeing that I
performed the unchecked return causing this problem.

Modified:
    trunk/main/pbx.c

Modified: trunk/main/pbx.c
URL: http://svnview.digium.com/svn/asterisk/trunk/main/pbx.c?view=diff&rev=367419&r1=367418&r2=367419
==============================================================================
--- trunk/main/pbx.c (original)
+++ trunk/main/pbx.c Wed May 23 15:39:22 2012
@@ -5105,6 +5105,7 @@
 	int autoloopflag;
 	int error = 0;		/* set an error conditions */
 	struct ast_pbx *pbx;
+	struct ast_callid *callid;
 
 	/* A little initial setup here */
 	if (ast_channel_pbx(c)) {
@@ -5116,17 +5117,24 @@
 		return -1;
 	}
 
-	if (!ast_read_threadstorage_callid()) {
+	callid = ast_read_threadstorage_callid();
+	/* If the thread isn't already associated with a callid, we should create that association. */
+	if (!callid) {
 		/* Associate new PBX thread with the channel call id if it is availble.
 		 * If not, create a new one instead.
 		 */
-		struct ast_callid *callid;
-		if (!(callid = ast_channel_callid(c))) {
+		callid = ast_channel_callid(c);
+		if (!callid) {
 			callid = ast_create_callid();
+			if (callid) {
+				ast_channel_callid_set(c, callid);
+			}
 		}
 		ast_callid_threadassoc_add(callid);
-		ast_channel_callid_set(c, callid);
 		callid = ast_callid_unref(callid);
+	} else {
+		/* Nothing to do here, The thread is already bound to a callid.  Let's just get rid of the reference. */
+		ast_callid_unref(callid);
 	}
 
 	ast_channel_pbx_set(c, pbx);




More information about the asterisk-commits mailing list