]> git.proxmox.com Git - qemu.git/commitdiff
ui: Plug memory leaks on parse_keyboard_layout() error path
authorMarkus Armbruster <armbru@redhat.com>
Fri, 11 Nov 2011 09:40:06 +0000 (10:40 +0100)
committerAnthony Liguori <aliguori@us.ibm.com>
Fri, 11 Nov 2011 18:49:51 +0000 (12:49 -0600)
Spotted by Coverity.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
ui/keymaps.c

index f54a11437b96761840a39eda1a2ec2a3ddaae382..f55a2aa46452cb5836bb8a6ccd79e455d407fbbe 100644 (file)
@@ -92,15 +92,17 @@ static kbd_layout_t *parse_keyboard_layout(const name2keysym_t *table,
     int len;
 
     filename = qemu_find_file(QEMU_FILE_TYPE_KEYMAP, language);
-
-    if (!k)
-       k = g_malloc0(sizeof(kbd_layout_t));
-    if (!(filename && (f = fopen(filename, "r")))) {
+    f = filename ? fopen(filename, "r") : NULL;
+    g_free(filename);
+    if (!f) {
        fprintf(stderr,
                "Could not read keymap file: '%s'\n", language);
        return NULL;
     }
-    g_free(filename);
+
+    if (!k)
+       k = g_malloc0(sizeof(kbd_layout_t));
+
     for(;;) {
        if (fgets(line, 1024, f) == NULL)
             break;