module-filter-apply: Fix a memory leak 98/128498/3
authorKimJeongYeon <jeongyeon.kim@samsung.com>
Wed, 10 May 2017 08:04:43 +0000 (17:04 +0900)
committeryoungseok lee <youngseok7.lee@samsung.com>
Fri, 26 May 2017 05:36:55 +0000 (05:36 +0000)
Dynamic memory allocated to 'module_name' and 'fltr' was being leaked.
Its now freed properly before return.

BugLink: https://bugs.freedesktop.org/show_bug.cgi?id=95293
Signed-off-by: Sachin Kumar Chauhan <sachin.kc@samsung.com>
Signed-off-by: Arun Raghavan <arun@arunraghavan.net>
This patch based on:
https://cgit.freedesktop.org/pulseaudio/pulseaudio/commit/?id=a19e1e5382ca9c193d9fa33356465b040f55a672

filter-apply: fix typo "what" -> "want"

This patch based on:
https://cgit.freedesktop.org/pulseaudio/pulseaudio/commit/?id=71b128aaeabfdb0b5845ef062d8ddfd56baa77a8

Note for tizen:
The purpose of these patches is that sync code with upstream.

Change-Id: I0a8e2de2312752520e868c0dc0e84fa31bd12a00

src/modules/module-filter-apply.c

index a0523a6..54651f0 100644 (file)
@@ -146,7 +146,7 @@ static const char* get_filter_name(pa_object *o, bool is_sink_input) {
     else
         pl = PA_SOURCE_OUTPUT(o)->proplist;
 
-    /* If the stream doesn't what any filter, then let it be. */
+    /* If the stream doesn't want any filter, then let it be. */
     if ((apply = pa_proplist_gets(pl, PA_PROP_FILTER_APPLY)) && !pa_streq(apply, "")) {
         const char* suppress = pa_proplist_gets(pl, PA_PROP_FILTER_SUPPRESS);
 
@@ -525,6 +525,8 @@ static pa_hook_result_t process(struct userdata *u, pa_object *o, bool is_sink_i
     pa_sink *sink = NULL;
     pa_source *source = NULL;
     pa_module *module = NULL;
+    char *module_name = NULL;
+    struct filter *fltr = NULL, *filter = NULL;
     pa_proplist *pl;
 
     if (is_sink_input) {
@@ -539,24 +541,20 @@ static pa_hook_result_t process(struct userdata *u, pa_object *o, bool is_sink_i
 
     /* If there is no sink/source yet, we can't do much */
     if ((is_sink_input && !sink) || (!is_sink_input && !source))
-        return PA_HOOK_OK;
+        goto done;
 
     /* If the stream doesn't want any filter, then let it be. */
     if ((want = get_filter_name(o, is_sink_input))) {
-        char *module_name;
-        struct filter *fltr, *filter;
-
         /* We need to ensure the SI is playing on a sink of this type
          * attached to the sink it's "officially" playing on */
 
         if (!module)
-            return PA_HOOK_OK;
+            goto done;
 
         module_name = pa_sprintf_malloc("module-%s", want);
         if (pa_streq(module->name, module_name)) {
             pa_log_debug("Stream appears to be playing on an appropriate sink already. Ignoring.");
-            pa_xfree(module_name);
-            return PA_HOOK_OK;
+            goto done;
         }
 
         /* If the stream originally did not have the filter.apply property set and is
@@ -588,9 +586,7 @@ static pa_hook_result_t process(struct userdata *u, pa_object *o, bool is_sink_i
 
         if (should_group_filter(fltr) && !find_paired_master(u, fltr, o, is_sink_input)) {
             pa_log_debug("Want group filtering but don't have enough streams.");
-            pa_xfree(module_name);
-            filter_free(fltr);
-            return PA_HOOK_OK;
+            goto done;
         }
 
         if (!(filter = pa_hashmap_get(u->filters, fltr))) {
@@ -614,14 +610,10 @@ static pa_hook_result_t process(struct userdata *u, pa_object *o, bool is_sink_i
             pa_xfree(args);
         }
 
-        filter_free(fltr);
-
         if (!filter) {
             pa_log("Unable to load %s", module_name);
-            pa_xfree(module_name);
-            return PA_HOOK_OK;
+            goto done;
         }
-        pa_xfree(module_name);
 
         /* We can move the stream now as we know the destination. If this
          * isn't true, we will do it later when the sink appears. */
@@ -630,8 +622,6 @@ static pa_hook_result_t process(struct userdata *u, pa_object *o, bool is_sink_i
             done_something = true;
         }
     } else {
-        struct filter *filter = NULL;
-
         /* The filter.apply property is not set. If the stream is nevertheless using a
          * filter sink/source, it either has been moved to the filter manually or the
          * user just removed the filter.apply property. */
@@ -654,6 +644,9 @@ done:
     if (done_something)
         trigger_housekeeping(u);
 
+    pa_xfree(module_name);
+    filter_free(fltr);
+
     return PA_HOOK_OK;
 }