From 1f1fb8eb6b3e9ce9a6d7b382f48ddb2349d98be6 Mon Sep 17 00:00:00 2001 From: Eero Nurkkala Date: Tue, 21 Jul 2020 11:22:39 +0300 Subject: [PATCH] tests: cpu-remap-test.c: fix memory leaks 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 --- src/tests/cpu-remap-test.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/tests/cpu-remap-test.c b/src/tests/cpu-remap-test.c index 7e2b7a498..28c3b34b2 100644 --- a/src/tests/cpu-remap-test.c +++ b/src/tests/cpu-remap-test.c @@ -26,6 +26,7 @@ #include #include #include +#include #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) {