filter-apply: Fix memory leak in process() 96/125096/1
authorKimJeongYeon <jeongyeon.kim@samsung.com>
Thu, 13 Apr 2017 22:36:13 +0000 (07:36 +0900)
committerKimJeongYeon <jeongyeon.kim@samsung.com>
Thu, 13 Apr 2017 22:38:25 +0000 (07:38 +0900)
fltr->name should be freed before freeing fltr. Because filter_free()
can never be called from other places without f set, the pa_assert()
can be removed and filter_free() can be used in process() as well.

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

Signed-off-by: KimJeongYeon <jeongyeon.kim@samsung.com>
Change-Id: I0b7ba3776efafe3453548b710cbf3c3ef5385851

src/modules/module-filter-apply.c

index 55019b2..bf3fbaa 100644 (file)
@@ -124,11 +124,11 @@ static struct filter *filter_new(const char *name, const char *group, pa_sink *s
 }
 
 static void filter_free(struct filter *f) {
-    pa_assert(f);
-
-    pa_xfree(f->name);
-    pa_xfree(f->group);
-    pa_xfree(f);
+    if (f) {
+        pa_xfree(f->name);
+        pa_xfree(f->group);
+        pa_xfree(f);
+    }
 }
 
 static const char* should_filter(pa_object *o, bool is_sink_input) {
@@ -502,6 +502,7 @@ static pa_hook_result_t process(struct userdata *u, pa_object *o, bool is_sink_i
 
         if (is_duplex_filter(fltr) && !find_paired_master(u, fltr, o, is_sink_input)) {
             pa_log_debug("Want group filtering but don't have enough streams.");
+            filter_free(fltr);
             return PA_HOOK_OK;
         }
 
@@ -526,7 +527,7 @@ static pa_hook_result_t process(struct userdata *u, pa_object *o, bool is_sink_i
             pa_xfree(args);
         }
 
-        pa_xfree(fltr);
+        filter_free(fltr);
 
         if (!filter) {
             pa_log("Unable to load %s", module_name);