From 019e78ba6ec6f402dffc6bc9683f461a11a52c28 Mon Sep 17 00:00:00 2001 From: Kevin Wolf Date: Mon, 17 May 2010 10:36:47 +0200 Subject: Fix error handling in qemu_read_config_file We need to close the file even in error case. While at it, make the callers catch all kind of errors. ENOENT is allowed for default config files, they are optional. Reported-by: Luiz Capitulino Signed-off-by: Kevin Wolf Signed-off-by: Anthony Liguori --- qemu-config.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'qemu-config.c') diff --git a/qemu-config.c b/qemu-config.c index d5008851..aa376d4 100644 --- a/qemu-config.c +++ b/qemu-config.c @@ -521,14 +521,18 @@ out: int qemu_read_config_file(const char *filename) { FILE *f = fopen(filename, "r"); + int ret; + if (f == NULL) { return -errno; } - if (qemu_config_parse(f, vm_config_groups, filename) != 0) { - return -EINVAL; - } + ret = qemu_config_parse(f, vm_config_groups, filename); fclose(f); - return 0; + if (ret == 0) { + return 0; + } else { + return -EINVAL; + } } -- cgit v1.1