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 <eero.nurkkala@offcode.fi>
This commit is contained in:
Eero Nurkkala 2020-07-21 11:22:39 +03:00
parent 9dd7f48b49
commit 1f1fb8eb6b

View file

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