tests: hashmap-test.c: fix memory leak
authorEero Nurkkala <eero.nurkkala@offcode.fi>
Tue, 21 Jul 2020 08:13:01 +0000 (11:13 +0300)
committerEero Nurkkala <eero.nurkkala@offcode.fi>
Tue, 21 Jul 2020 11:56:59 +0000 (14:56 +0300)
When compiled with ASAN: -O1 -fsanitize=address -fno-omit-frame-pointer,
the following issue is seen:

==14272==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 1072 byte(s) in 1 object(s) allocated from:
    #0 0x7f0180966d28 in __interceptor_calloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xded28)
    #1 0x7f018039f043 in pa_xmalloc0 pulse/xmalloc.c:74
    #2 0x7f01803c5cc8 in pa_hashmap_new_full pulsecore/hashmap.c:61
    #3 0x7f01803c5df9 in pa_hashmap_new pulsecore/hashmap.c:76
    #4 0x556ee75ff7f4 in remove_all_test tests/hashmap-test.c:96
    #5 0x556ee7602965 in srunner_run (/home/eenurkka/pulse/pulseaudio/src/.libs/hashmap-test+0x6965)

SUMMARY: AddressSanitizer: 1072 byte(s) leaked in 1 allocation(s).

Fix it by freeing the resource properly.

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

index 39d3e85..f460bd4 100644 (file)
@@ -108,6 +108,8 @@ START_TEST(remove_all_test)
         if ((size = pa_hashmap_size(map)) != 0) {
             ck_abort_msg("Hashmap has wrong size; got %u, want 0", size);
         }
+
+        pa_hashmap_free(map);
     }
 END_TEST