From f2d3476eba17486c42357ba25c36bd26e627d1d7 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Fri, 11 Nov 2011 10:40:06 +0100 Subject: [PATCH] ui: Plug memory leaks on parse_keyboard_layout() error path Spotted by Coverity. Signed-off-by: Markus Armbruster Signed-off-by: Anthony Liguori --- ui/keymaps.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/ui/keymaps.c b/ui/keymaps.c index f54a11437b..f55a2aa464 100644 --- a/ui/keymaps.c +++ b/ui/keymaps.c @@ -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;