[asterisk-commits] russell: trunk r105569 - in /trunk: ./ channels/chan_local.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Mar 3 11:06:35 CST 2008


Author: russell
Date: Mon Mar  3 11:06:35 2008
New Revision: 105569

URL: http://svn.digium.com/view/asterisk?view=rev&rev=105569
Log:
Merged revisions 105568 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.4

........
r105568 | russell | 2008-03-03 11:05:16 -0600 (Mon, 03 Mar 2008) | 3 lines

Fix a potential memory leak of the local_pvt struct when ast_channel allocation
fails.  Also, in passing, centralize the code necessary to destroy a local_pvt.

........

Modified:
    trunk/   (props changed)
    trunk/channels/chan_local.c

Propchange: trunk/
------------------------------------------------------------------------------
Binary property 'branch-1.4-merged' - no diff available.

Modified: trunk/channels/chan_local.c
URL: http://svn.digium.com/view/asterisk/trunk/channels/chan_local.c?view=diff&rev=105569&r1=105568&r2=105569
==============================================================================
--- trunk/channels/chan_local.c (original)
+++ trunk/channels/chan_local.c Mon Mar  3 11:06:35 2008
@@ -157,6 +157,13 @@
 	return res;
 }
 
+static struct local_pvt *local_pvt_destroy(struct local_pvt *pvt)
+{
+	ast_mutex_destroy(&pvt->lock);
+	ast_free(pvt);
+	return NULL;
+}
+
 static int local_queue_frame(struct local_pvt *p, int isoutbound, struct ast_frame *f, struct ast_channel *us)
 {
 	struct ast_channel *other = NULL;
@@ -170,8 +177,7 @@
 		/* We had a glare on the hangup.  Forget all this business,
 		return and destroy p.  */
 		ast_mutex_unlock(&p->lock);
-		ast_mutex_destroy(&p->lock);
-		ast_free(p);
+		p = local_pvt_destroy(p);
 		return -1;
 	}
 	if (!other) {
@@ -548,8 +554,7 @@
 		ast_mutex_unlock(&p->lock);
 		/* And destroy */
 		if (!glaredetect) {
-			ast_mutex_destroy(&p->lock);
-			ast_free(p);
+			p = local_pvt_destroy(p);
 		}
 		return 0;
 	}
@@ -605,9 +610,7 @@
 
 	if (!ast_exists_extension(NULL, tmp->context, tmp->exten, 1, NULL)) {
 		ast_log(LOG_NOTICE, "No such extension/context %s@%s creating local channel\n", tmp->exten, tmp->context);
-		ast_mutex_destroy(&tmp->lock);
-		ast_free(tmp);
-		tmp = NULL;
+		tmp = local_pvt_destroy(tmp);
 	} else {
 		/* Add to list */
 		AST_LIST_LOCK(&locals);
@@ -682,7 +685,6 @@
 	return tmp;
 }
 
-
 /*! \brief Part of PBX interface */
 static struct ast_channel *local_request(const char *type, int format, void *data, int *cause)
 {
@@ -690,8 +692,10 @@
 	struct ast_channel *chan = NULL;
 
 	/* Allocate a new private structure and then Asterisk channel */
-	if ((p = local_alloc(data, format)))
-		chan = local_new(p, AST_STATE_DOWN);
+	if ((p = local_alloc(data, format))) {
+		if (!(chan = local_new(p, AST_STATE_DOWN)))
+			p = local_pvt_destroy(p);
+	}
 
 	return chan;
 }




More information about the asterisk-commits mailing list