Skip to contentSkip to conversation

qemu-keymap: Silence memory leak warning from Clang's sanitizer

PATCH In review Thomas Huth 2 participants 2 messages Feb 21, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 qemu-keymap: Silence memory leak warning from Clang's sanitizer

When compiling QEMU with "--enable-sanitizers --enable-xkbcommon --cc=clang" there is a memory leak warning when running qemu-keymap:

 $ ./qemu-keymap -f pc-bios/keymaps/de -l de

=================================================================
==610321==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 136 byte(s) in 1 object(s) allocated from:

     #0 0x5642830d0820 in __interceptor_calloc.part.11 asan_malloc_linux.cpp.o
     #1 0x7f31873b8d2b in xkb_state_new (/lib64/libxkbcommon.so.0+0x1dd2b) (BuildId: dd32581e2248833243f3f646324ae9b98469f025)

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

It can be silenced by properly releasing the "state" again after it has been used.

---
 qemu-keymap.c | 2 ++
 1 file changed, 2 insertions(+)
qemu-keymap.c +2 -0
index 4095b654a6..229866e004 100644
@@ -226,6 +226,8 @@ int main(int argc, char *argv[])
 
     state = xkb_state_new(map);
     xkb_keymap_key_for_each(map, walk_map, state);
+    xkb_state_unref(state);
+    state = NULL;
 
     /* add quirks */
     fprintf(outfile,
Signature · 1 line
2.31.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 13 lines · Thomas Huth

When compiling QEMU with "--enable-sanitizers --enable-xkbcommon --cc=clang" there is a memory leak warning when running qemu-keymap:

 $ ./qemu-keymap -f pc-bios/keymaps/de -l de

=================================================================
==610321==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 136 byte(s) in 1 object(s) allocated from:

     #0 0x5642830d0820 in __interceptor_calloc.part.11 asan_malloc_linux.cpp.o
     #1 0x7f31873b8d2b in xkb_state_new (/lib64/libxkbcommon.so.0+0x1dd2b) (BuildId: dd32581e2248833243f3f646324ae9b98469f025)
Quoted 6 lines

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

It can be silenced by properly releasing the "state" again after it has been used.

The leak is a "trivial" one in that we allocate only one object and we're going to immediately exit anyway.

thanks
-- PMM