ui: Plug memory leaks on parse_keyboard_layout() error path
Spotted by Coverity.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
diff --git a/ui/keymaps.c b/ui/keymaps.c
index f54a114..f55a2aa 100644
--- a/ui/keymaps.c
+++ b/ui/keymaps.c
@@ -92,15 +92,17 @@
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;