When building with `--enable-sanitizers`, I was getting quite a few memory leak crashes from ASAN:
[21/574] Generating pc-bios/keymaps/fr-ch with a custom command FAILED: pc-bios/keymaps/fr-ch /home/dxu/dev/qemu/build/qemu-keymap -f pc-bios/keymaps/fr-ch -l ch -v fr ================================================================= ==3232549==ERROR: LeakSanitizer: detected memory leaks Direct leak of 1424 byte(s) in 1 object(s) allocated from: #0 0x7f32636bf411 in __interceptor_calloc /usr/src/debug/gcc/gcc/... #1 0x7f32635db73e (/usr/lib/libxkbcommon.so.0+0x2273e) Fix leaks by correctly decrementing refcounts on xkb structs. Signed-off-by: Daniel Xu <d...@dxuuu.xyz> --- qemu-keymap.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/qemu-keymap.c b/qemu-keymap.c index 229866e004..ed8cee3467 100644 --- a/qemu-keymap.c +++ b/qemu-keymap.c @@ -203,6 +203,7 @@ int main(int argc, char *argv[]) map = xkb_keymap_new_from_names(ctx, &names, XKB_KEYMAP_COMPILE_NO_FLAGS); if (!map) { /* libxkbcommon prints error */ + xkb_context_unref(ctx); exit(1); } @@ -227,7 +228,11 @@ int main(int argc, char *argv[]) state = xkb_state_new(map); xkb_keymap_key_for_each(map, walk_map, state); xkb_state_unref(state); + xkb_keymap_unref(map); + xkb_context_unref(ctx); state = NULL; + map = NULL; + ctx = NULL; /* add quirks */ fprintf(outfile, -- 2.39.1