aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarkus Armbruster <armbru@redhat.com>2011-11-11 10:40:06 +0100
committerAnthony Liguori <aliguori@us.ibm.com>2011-11-11 12:49:51 -0600
commitf2d3476eba17486c42357ba25c36bd26e627d1d7 (patch)
tree2a159f85415966a428714407ada1a72632b273da
parenta4e26048526d8d5b181f9a0a7d4f82b8441c5dfd (diff)
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>
-rw-r--r--ui/keymaps.c12
1 files 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;