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 <jan.kiszka@siemens.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
This commit is contained in:
parent
059b8b1eb6
commit
229609dd45
39
sdl.c
39
sdl.c
|
@ -268,32 +268,35 @@ static uint8_t sdl_keyevent_to_keycode(const SDL_KeyboardEvent *ev)
|
||||||
static int check_for_evdev(void)
|
static int check_for_evdev(void)
|
||||||
{
|
{
|
||||||
SDL_SysWMinfo info;
|
SDL_SysWMinfo info;
|
||||||
XkbDescPtr desc;
|
XkbDescPtr desc = NULL;
|
||||||
int has_evdev = 0;
|
int has_evdev = 0;
|
||||||
const char *keycodes;
|
char *keycodes = NULL;
|
||||||
|
|
||||||
SDL_VERSION(&info.version);
|
SDL_VERSION(&info.version);
|
||||||
if (!SDL_GetWMInfo(&info))
|
if (!SDL_GetWMInfo(&info)) {
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
desc = XkbGetKeyboard(info.info.x11.display,
|
desc = XkbGetKeyboard(info.info.x11.display,
|
||||||
XkbGBN_AllComponentsMask,
|
XkbGBN_AllComponentsMask,
|
||||||
XkbUseCoreKbd);
|
XkbUseCoreKbd);
|
||||||
if (desc == NULL || desc->names == NULL)
|
if (desc && desc->names) {
|
||||||
return 0;
|
keycodes = XGetAtomName(info.info.x11.display, desc->names->keycodes);
|
||||||
|
if (keycodes == NULL) {
|
||||||
keycodes = XGetAtomName(info.info.x11.display, desc->names->keycodes);
|
fprintf(stderr, "could not lookup keycode name\n");
|
||||||
if (keycodes == NULL)
|
} else if (strstart(keycodes, "evdev", NULL)) {
|
||||||
fprintf(stderr, "could not lookup keycode name\n");
|
has_evdev = 1;
|
||||||
else if (strstart(keycodes, "evdev", NULL))
|
} else if (!strstart(keycodes, "xfree86", NULL)) {
|
||||||
has_evdev = 1;
|
fprintf(stderr, "unknown keycodes `%s', please report to "
|
||||||
else if (!strstart(keycodes, "xfree86", NULL))
|
"qemu-devel@nongnu.org\n", keycodes);
|
||||||
fprintf(stderr,
|
}
|
||||||
"unknown keycodes `%s', please report to qemu-devel@nongnu.org\n",
|
}
|
||||||
keycodes);
|
|
||||||
|
|
||||||
XkbFreeClientMap(desc, XkbGBN_AllComponentsMask, True);
|
|
||||||
|
|
||||||
|
if (desc) {
|
||||||
|
XkbFreeKeyboard(desc, XkbGBN_AllComponentsMask, True);
|
||||||
|
}
|
||||||
|
if (keycodes) {
|
||||||
|
XFree(keycodes);
|
||||||
|
}
|
||||||
return has_evdev;
|
return has_evdev;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
|
Reference in New Issue