[svn-commits] rmudgett: branch 1.8 r419684 - in /branches/1.8: apps/ funcs/

SVN commits to the Digium repositories svn-commits at lists.digium.com
Mon Jul 28 13:28:00 CDT 2014


Author: rmudgett
Date: Mon Jul 28 13:27:56 2014
New Revision: 419684

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=419684
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/

Modified:
    branches/1.8/apps/app_queue.c
    branches/1.8/apps/app_speech_utils.c
    branches/1.8/funcs/func_frame_trace.c

Modified: branches/1.8/apps/app_queue.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.8/apps/app_queue.c?view=diff&rev=419684&r1=419683&r2=419684
==============================================================================
--- branches/1.8/apps/app_queue.c (original)
+++ branches/1.8/apps/app_queue.c Mon Jul 28 13:27:56 2014
@@ -4573,6 +4573,7 @@
 	/* No need to lock the channels because they are already locked in ast_do_masquerade */
 	if ((datastore = ast_channel_datastore_find(old_chan, &queue_transfer_info, NULL))) {
 		ast_channel_datastore_remove(old_chan, datastore);
+		/* Datastore is freed in try_calling() */
 	} else {
 		ast_log(LOG_WARNING, "Can't find the queue_transfer datastore.\n");
 	}
@@ -5445,6 +5446,7 @@
 			}
 			if ((tds = ast_channel_datastore_find(qe->chan, &queue_transfer_info, NULL))) {	
 				ast_channel_datastore_remove(qe->chan, tds);
+				/* tds was added by setup_transfer_datastore() and is freed below. */
 			}
 			ast_channel_unlock(qe->chan);
 			update_queue(qe->parent, member, callcompletedinsl, (time(NULL) - callstart));

Modified: branches/1.8/apps/app_speech_utils.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.8/apps/app_speech_utils.c?view=diff&rev=419684&r1=419683&r2=419684
==============================================================================
--- branches/1.8/apps/app_speech_utils.c (original)
+++ branches/1.8/apps/app_speech_utils.c Mon Jul 28 13:27:56 2014
@@ -289,13 +289,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 */
@@ -519,7 +550,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;
 }
@@ -662,7 +695,6 @@
 	int oldreadformat = AST_FORMAT_SLINEAR;
 	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 };
@@ -891,11 +923,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);
@@ -908,22 +936,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: branches/1.8/funcs/func_frame_trace.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.8/funcs/func_frame_trace.c?view=diff&rev=419684&r1=419683&r2=419684
==============================================================================
--- branches/1.8/funcs/func_frame_trace.c (original)
+++ branches/1.8/funcs/func_frame_trace.c Mon Jul 28 13:27:56 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))) {




More information about the svn-commits mailing list