From 229609dd45ee572fb343366a5bf440afb25cf614 Mon Sep 17 00:00:00 2001 From: Jan Kiszka Date: Sat, 27 Jun 2009 09:59:40 +0200 Subject: sdl: Fix memory leakage Valgrind was so kind to remark that no one bothers to release keycodes after use and that something is fishy about cleaning up the requested keyboard descriptor. With this patch applied, we no longer leak about 12k during startup. Signed-off-by: Jan Kiszka Signed-off-by: Anthony Liguori --- sdl.c | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) (limited to 'sdl.c') diff --git a/sdl.c b/sdl.c index d81399e512..6d88cd5255 100644 --- a/sdl.c +++ b/sdl.c @@ -268,32 +268,35 @@ static uint8_t sdl_keyevent_to_keycode(const SDL_KeyboardEvent *ev) static int check_for_evdev(void) { SDL_SysWMinfo info; - XkbDescPtr desc; + XkbDescPtr desc = NULL; int has_evdev = 0; - const char *keycodes; + char *keycodes = NULL; SDL_VERSION(&info.version); - if (!SDL_GetWMInfo(&info)) + if (!SDL_GetWMInfo(&info)) { return 0; - + } desc = XkbGetKeyboard(info.info.x11.display, XkbGBN_AllComponentsMask, XkbUseCoreKbd); - if (desc == NULL || desc->names == NULL) - return 0; - - keycodes = XGetAtomName(info.info.x11.display, desc->names->keycodes); - if (keycodes == NULL) - fprintf(stderr, "could not lookup keycode name\n"); - else if (strstart(keycodes, "evdev", NULL)) - has_evdev = 1; - else if (!strstart(keycodes, "xfree86", NULL)) - fprintf(stderr, - "unknown keycodes `%s', please report to qemu-devel@nongnu.org\n", - keycodes); - - XkbFreeClientMap(desc, XkbGBN_AllComponentsMask, True); + if (desc && desc->names) { + keycodes = XGetAtomName(info.info.x11.display, desc->names->keycodes); + if (keycodes == NULL) { + fprintf(stderr, "could not lookup keycode name\n"); + } else if (strstart(keycodes, "evdev", NULL)) { + has_evdev = 1; + } else if (!strstart(keycodes, "xfree86", NULL)) { + fprintf(stderr, "unknown keycodes `%s', please report to " + "qemu-devel@nongnu.org\n", keycodes); + } + } + if (desc) { + XkbFreeKeyboard(desc, XkbGBN_AllComponentsMask, True); + } + if (keycodes) { + XFree(keycodes); + } return has_evdev; } #else -- cgit v1.2.3