[asterisk-commits] rmudgett: trunk r419688 - in /trunk: ./ apps/ funcs/ main/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Jul 28 13:58:52 CDT 2014


Author: rmudgett
Date: Mon Jul 28 13:58:43 2014
New Revision: 419688

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=419688
Log:
datastores: Audit ast_channel_datastore_remove usage.

Audit of v1.8 usage of ast_channel_datastore_remove() for datastore memory
leaks.

* Fixed leaks in app_speech_utils and func_frame_trace.

* Fixed app_speech_utils not locking the channel when accessing the
channel datastore list.

Review: https://reviewboard.asterisk.org/r/3859/

Audit of v11 usage of ast_channel_datastore_remove() for datastore memory
leaks.

* Fixed leak in func_jitterbuffer.  (Was not in v12)

Review: https://reviewboard.asterisk.org/r/3860/

Audit of v12 usage of ast_channel_datastore_remove() for datastore memory
leaks.

* Fixed leaks in abstract_jb.

* Fixed leak in ast_channel_unsuppress().  Used by ARI mute control and
res_mutestream.

* Fixed ref leak in ast_channel_suppress().  Used by ARI mute control and
res_mutestream.

Review: https://reviewboard.asterisk.org/r/3861/
........

Merged revisions 419684 from http://svn.asterisk.org/svn/asterisk/branches/1.8
........

Merged revisions 419685 from http://svn.asterisk.org/svn/asterisk/branches/11
........

Merged revisions 419686 from http://svn.asterisk.org/svn/asterisk/branches/12

Modified:
    trunk/   (props changed)
    trunk/apps/app_speech_utils.c
    trunk/funcs/func_frame_trace.c
    trunk/main/abstract_jb.c
    trunk/main/channel.c

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

Modified: trunk/apps/app_speech_utils.c
URL: http://svnview.digium.com/svn/asterisk/trunk/apps/app_speech_utils.c?view=diff&rev=419688&r1=419687&r2=419688
==============================================================================
--- trunk/apps/app_speech_utils.c (original)
+++ trunk/apps/app_speech_utils.c Mon Jul 28 13:58:43 2014
@@ -290,13 +290,44 @@
 		return NULL;
 	}
 
+	ast_channel_lock(chan);
 	datastore = ast_channel_datastore_find(chan, &speech_datastore, NULL);
+	ast_channel_unlock(chan);
 	if (datastore == NULL) {
 		return NULL;
 	}
 	speech = datastore->data;
 
 	return speech;
+}
+
+/*!
+ * \internal
+ * \brief Destroy the speech datastore on the given channel.
+ *
+ * \param chan Channel to destroy speech datastore.
+ *
+ * \retval 0 on success.
+ * \retval -1 not found.
+ */
+static int speech_datastore_destroy(struct ast_channel *chan)
+{
+	struct ast_datastore *datastore;
+	int res;
+
+	ast_channel_lock(chan);
+	datastore = ast_channel_datastore_find(chan, &speech_datastore, NULL);
+	if (datastore) {
+		ast_channel_datastore_remove(chan, datastore);
+	}
+	ast_channel_unlock(chan);
+	if (datastore) {
+		ast_datastore_free(datastore);
+		res = 0;
+	} else {
+		res = -1;
+	}
+	return res;
 }
 
 /* Helper function to find a specific speech recognition result by number and nbest alternative */
@@ -532,7 +563,9 @@
 	}
 	pbx_builtin_setvar_helper(chan, "ERROR", NULL);
 	datastore->data = speech;
+	ast_channel_lock(chan);
 	ast_channel_datastore_add(chan, datastore);
+	ast_channel_unlock(chan);
 
 	return 0;
 }
@@ -675,7 +708,6 @@
 	RAII_VAR(struct ast_format *, oldreadformat, NULL, ao2_cleanup);
 	char dtmf[AST_MAX_EXTENSION] = "";
 	struct timeval start = { 0, 0 }, current;
-	struct ast_datastore *datastore = NULL;
 	char *parse, *filename_tmp = NULL, *filename = NULL, tmp[2] = "", dtmf_terminator = '#';
 	const char *tmp2 = NULL;
 	struct ast_flags options = { 0 };
@@ -904,11 +936,7 @@
 
 	/* See if it was because they hung up */
 	if (done == 3) {
-		/* Destroy speech structure */
-		ast_speech_destroy(speech);
-		datastore = ast_channel_datastore_find(chan, &speech_datastore, NULL);
-		if (datastore != NULL)
-			ast_channel_datastore_remove(chan, datastore);
+		speech_datastore_destroy(chan);
 	} else {
 		/* Channel is okay so restore read format */
 		ast_set_read_format(chan, oldreadformat);
@@ -921,22 +949,10 @@
 /*! \brief SpeechDestroy() Dialplan Application */
 static int speech_destroy(struct ast_channel *chan, const char *data)
 {
-	int res = 0;
-	struct ast_speech *speech = find_speech(chan);
-	struct ast_datastore *datastore = NULL;
-
-	if (speech == NULL)
-		return -1;
-
-	/* Destroy speech structure */
-	ast_speech_destroy(speech);
-
-	datastore = ast_channel_datastore_find(chan, &speech_datastore, NULL);
-	if (datastore != NULL) {
-		ast_channel_datastore_remove(chan, datastore);
-	}
-
-	return res;
+	if (!chan) {
+		return -1;
+	}
+	return speech_datastore_destroy(chan);
 }
 
 static int unload_module(void)

Modified: trunk/funcs/func_frame_trace.c
URL: http://svnview.digium.com/svn/asterisk/trunk/funcs/func_frame_trace.c?view=diff&rev=419688&r1=419687&r2=419688
==============================================================================
--- trunk/funcs/func_frame_trace.c (original)
+++ trunk/funcs/func_frame_trace.c Mon Jul 28 13:58:43 2014
@@ -185,6 +185,7 @@
 			id = datastore->data;
 			ast_framehook_detach(chan, *id);
 			ast_channel_datastore_remove(chan, datastore);
+			ast_datastore_free(datastore);
 		}
 
 		if (!(datastore = ast_datastore_alloc(&frame_trace_datastore, NULL))) {

Modified: trunk/main/abstract_jb.c
URL: http://svnview.digium.com/svn/asterisk/trunk/main/abstract_jb.c?view=diff&rev=419688&r1=419687&r2=419688
==============================================================================
--- trunk/main/abstract_jb.c (original)
+++ trunk/main/abstract_jb.c Mon Jul 28 13:58:43 2014
@@ -1055,6 +1055,7 @@
 			id = datastore->data;
 			ast_framehook_detach(chan, *id);
 			ast_channel_datastore_remove(chan, datastore);
+			ast_datastore_free(datastore);
 		}
 		ast_channel_unlock(chan);
 		return;
@@ -1087,6 +1088,7 @@
 			id = datastore->data;
 			ast_framehook_detach(chan, *id);
 			ast_channel_datastore_remove(chan, datastore);
+			ast_datastore_free(datastore);
 		}
 
 		if (!(datastore = ast_datastore_alloc(&jb_datastore, NULL))) {
@@ -1112,6 +1114,4 @@
 		framedata = NULL;
 	}
 	ast_channel_unlock(chan);
-
-	return;
-}
+}

Modified: trunk/main/channel.c
URL: http://svnview.digium.com/svn/asterisk/trunk/main/channel.c?view=diff&rev=419688&r1=419687&r2=419688
==============================================================================
--- trunk/main/channel.c (original)
+++ trunk/main/channel.c Mon Jul 28 13:58:43 2014
@@ -10415,10 +10415,7 @@
 
 	if ((datastore = ast_channel_datastore_find(chan, datastore_info, NULL))) {
 		suppress = datastore->data;
-		ao2_ref(suppress, +1);
-
 		suppress->direction |= direction;
-
 		return 0;
 	}
 
@@ -10450,12 +10447,11 @@
 		return -1;
 	}
 
-	datastore->data = suppress;
-
-	ast_channel_datastore_add(chan, datastore);
-
 	/* and another ref for the datastore */
 	ao2_ref(suppress, +1);
+	datastore->data = suppress;
+
+	ast_channel_datastore_add(chan, datastore);
 
 	return 0;
 }
@@ -10484,6 +10480,7 @@
 		/* Nothing left to suppress.  Bye! */
 		ast_framehook_detach(chan, suppress->framehook_id);
 		ast_channel_datastore_remove(chan, datastore);
+		ast_datastore_free(datastore);
 	}
 
 	return 0;




More information about the asterisk-commits mailing list