tests: cpu-remap-test.c: fix memory leaks
authorEero Nurkkala <eero.nurkkala@offcode.fi>
Tue, 21 Jul 2020 08:22:39 +0000 (11:22 +0300)
committerEero Nurkkala <eero.nurkkala@offcode.fi>
Tue, 21 Jul 2020 11:57:05 +0000 (14:57 +0300)
When compiled with ASAN: -O1 -fsanitize=address -fno-omit-frame-pointer,
the following issues are seen:

==17217==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 32 byte(s) in 1 object(s) allocated from:
    #0 0x7fceba414b40 in __interceptor_malloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xdeb40)
    #1 0x7fceb9b3eac9 in pa_xmalloc pulse/xmalloc.c:63
    #2 0x7fceb9b3ed22 in pa_xmemdup pulse/xmalloc.c:94
    #3 0x7fceb9e1eed5 in _pa_xnewdup_internal pulse/xmalloc.h:86
    #4 0x7fceb9e1eed5 in init_remap_c pulsecore/remap.c:580
    #5 0x7fceb9e1efe5 in pa_init_remap_func pulsecore/remap.c:608
    #6 0x5574e72422b7 in remap_init2_test_channels tests/cpu-remap-test.c:303
    #7 0x5574e7242420 in rearrange_special_test tests/cpu-remap-test.c:345
    #8 0x5574e7245ce5 in srunner_run (/home/eenurkka/pulse/pulseaudio/src/.libs/cpu-remap-test+0x9ce5)
...
SUMMARY: AddressSanitizer: 192 byte(s) leaked in 6 allocation(s).

Fix those issues by freeing the allocated resources properly.

Signed-off-by: Eero Nurkkala <eero.nurkkala@offcode.fi>
src/tests/cpu-remap-test.c

index 7e2b7a49819a153f4b7e8fe9435743798851c11a..28c3b34b2d3fd26aaae93a857906cae9c739f702 100644 (file)
@@ -26,6 +26,7 @@
 #include <pulsecore/random.h>
 #include <pulsecore/macro.h>
 #include <pulsecore/remap.h>
+#include <pulse/xmalloc.h>
 
 #include "runtime-test-util.h"
 
@@ -290,7 +291,7 @@ static void remap_init2_test_channels(
         bool rearrange) {
 
     pa_cpu_info cpu_info = { PA_CPU_UNDEFINED, {}, false };
-    pa_remap_t remap_orig, remap_func;
+    pa_remap_t remap_orig, remap_func = {0};
 
     cpu_info.force_generic_code = true;
     pa_remap_func_init(&cpu_info);
@@ -303,6 +304,8 @@ static void remap_init2_test_channels(
     pa_init_remap_func(&remap_func);
 
     remap_test_channels(&remap_func, &remap_orig);
+
+    pa_xfree(remap_func.state);
 }
 
 START_TEST (remap_special_test) {