Commit 229609dd45ee572fb343366a5bf440afb25cf614

Authored by Jan Kiszka
Committed by Anthony Liguori
1 parent 059b8b1e

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>
Showing 1 changed file with 21 additions and 18 deletions
... ... @@ -268,32 +268,35 @@ static uint8_t sdl_keyevent_to_keycode(const SDL_KeyboardEvent *ev)
268 268 static int check_for_evdev(void)
269 269 {
270 270 SDL_SysWMinfo info;
271   - XkbDescPtr desc;
  271 + XkbDescPtr desc = NULL;
272 272 int has_evdev = 0;
273   - const char *keycodes;
  273 + char *keycodes = NULL;
274 274  
275 275 SDL_VERSION(&info.version);
276   - if (!SDL_GetWMInfo(&info))
  276 + if (!SDL_GetWMInfo(&info)) {
277 277 return 0;
278   -
  278 + }
279 279 desc = XkbGetKeyboard(info.info.x11.display,
280 280 XkbGBN_AllComponentsMask,
281 281 XkbUseCoreKbd);
282   - if (desc == NULL || desc->names == NULL)
283   - return 0;
284   -
285   - keycodes = XGetAtomName(info.info.x11.display, desc->names->keycodes);
286   - if (keycodes == NULL)
287   - fprintf(stderr, "could not lookup keycode name\n");
288   - else if (strstart(keycodes, "evdev", NULL))
289   - has_evdev = 1;
290   - else if (!strstart(keycodes, "xfree86", NULL))
291   - fprintf(stderr,
292   - "unknown keycodes `%s', please report to qemu-devel@nongnu.org\n",
293   - keycodes);
294   -
295   - XkbFreeClientMap(desc, XkbGBN_AllComponentsMask, True);
  282 + if (desc && desc->names) {
  283 + keycodes = XGetAtomName(info.info.x11.display, desc->names->keycodes);
  284 + if (keycodes == NULL) {
  285 + fprintf(stderr, "could not lookup keycode name\n");
  286 + } else if (strstart(keycodes, "evdev", NULL)) {
  287 + has_evdev = 1;
  288 + } else if (!strstart(keycodes, "xfree86", NULL)) {
  289 + fprintf(stderr, "unknown keycodes `%s', please report to "
  290 + "qemu-devel@nongnu.org\n", keycodes);
  291 + }
  292 + }
296 293  
  294 + if (desc) {
  295 + XkbFreeKeyboard(desc, XkbGBN_AllComponentsMask, True);
  296 + }
  297 + if (keycodes) {
  298 + XFree(keycodes);
  299 + }
297 300 return has_evdev;
298 301 }
299 302 #else
... ...