]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
datastores: Audit ast_channel_datastore_remove usage.
authorRichard Mudgett <rmudgett@digium.com>
Mon, 28 Jul 2014 18:50:14 +0000 (18:50 +0000)
committerRichard Mudgett <rmudgett@digium.com>
Mon, 28 Jul 2014 18:50:14 +0000 (18:50 +0000)
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

git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/12@419686 65c4cc65-6c06-0410-ace0-fbb531ad65f3

apps/app_speech_utils.c
funcs/func_frame_trace.c
main/abstract_jb.c
main/channel.c

index e9ca63ea9177a7e6995f7d454fda01c6b5555305..0d363659663bdb320053aaee6412da00a5803d58 100644 (file)
@@ -290,7 +290,9 @@ static struct ast_speech *find_speech(struct ast_channel *chan)
                return NULL;
        }
 
+       ast_channel_lock(chan);
        datastore = ast_channel_datastore_find(chan, &speech_datastore, NULL);
+       ast_channel_unlock(chan);
        if (datastore == NULL) {
                return NULL;
        }
@@ -299,6 +301,35 @@ static struct ast_speech *find_speech(struct ast_channel *chan)
        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 */
 static struct ast_speech_result *find_result(struct ast_speech_result *results, char *result_num)
 {
@@ -532,7 +563,9 @@ static int speech_create(struct ast_channel *chan, const char *data)
        }
        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 @@ static int speech_background(struct ast_channel *chan, const char *data)
        struct ast_format oldreadformat;
        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 };
@@ -905,11 +937,7 @@ static int speech_background(struct ast_channel *chan, const char *data)
 
        /* 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);
@@ -922,22 +950,10 @@ static int speech_background(struct ast_channel *chan, const char *data)
 /*! \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)
+       if (!chan) {
                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;
+       return speech_datastore_destroy(chan);
 }
 
 static int unload_module(void)
index ecebde4df0c4dbe797b3017aa9753fa3fc7a3736..36a98d649d888d2e3f4b2bb5c8b93d679c564b52 100644 (file)
@@ -185,6 +185,7 @@ static int frame_trace_helper(struct ast_channel *chan, const char *cmd, char *d
                        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))) {
index 7841b6a4e74d281a0dccb65a7a2eac783d44a287..318498401aab883fb0156452997b282417efc4f1 100644 (file)
@@ -1052,6 +1052,7 @@ void ast_jb_create_framehook(struct ast_channel *chan, struct ast_jb_conf *jb_co
                        id = datastore->data;
                        ast_framehook_detach(chan, *id);
                        ast_channel_datastore_remove(chan, datastore);
+                       ast_datastore_free(datastore);
                }
                ast_channel_unlock(chan);
                return;
@@ -1084,6 +1085,7 @@ void ast_jb_create_framehook(struct ast_channel *chan, struct ast_jb_conf *jb_co
                        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))) {
@@ -1109,6 +1111,4 @@ void ast_jb_create_framehook(struct ast_channel *chan, struct ast_jb_conf *jb_co
                framedata = NULL;
        }
        ast_channel_unlock(chan);
-
-       return;
 }
index e05a5a1088918398d7ccb387d0bb0cdc1a35bd2c..40a25313e661b01a2fd99fe92707369e54fbb6a6 100644 (file)
@@ -10381,10 +10381,7 @@ int ast_channel_suppress(struct ast_channel *chan, unsigned int direction, enum
 
        if ((datastore = ast_channel_datastore_find(chan, datastore_info, NULL))) {
                suppress = datastore->data;
-               ao2_ref(suppress, +1);
-
                suppress->direction |= direction;
-
                return 0;
        }
 
@@ -10416,13 +10413,12 @@ int ast_channel_suppress(struct ast_channel *chan, unsigned int direction, enum
                return -1;
        }
 
+       /* and another ref for the datastore */
+       ao2_ref(suppress, +1);
        datastore->data = suppress;
 
        ast_channel_datastore_add(chan, datastore);
 
-       /* and another ref for the datastore */
-       ao2_ref(suppress, +1);
-
        return 0;
 }
 
@@ -10450,6 +10446,7 @@ int ast_channel_unsuppress(struct ast_channel *chan, unsigned int direction, enu
                /* Nothing left to suppress.  Bye! */
                ast_framehook_detach(chan, suppress->framehook_id);
                ast_channel_datastore_remove(chan, datastore);
+               ast_datastore_free(datastore);
        }
 
        return 0;