aboutsummaryrefslogtreecommitdiff
path: root/exec.c
diff options
context:
space:
mode:
authorPaolo Bonzini <pbonzini@redhat.com>2016-03-17 15:53:13 +0100
committerPaolo Bonzini <pbonzini@redhat.com>2016-03-22 22:20:18 +0100
commit5c3ece79cd0b7b4ed065f4285e7a0262bbfc283b (patch)
tree10ea4cbc22d21a21029798972263ea5dff6895a0 /exec.c
parent8526e1f4e418443a4d6ed0714487e47d45ef9c98 (diff)
exec: fix error handling in file_ram_alloc
One instance of double closing, and invalid close(-1) in some cases of "goto error". Reviewed-by: Laszlo Ersek <lersek@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'exec.c')
-rw-r--r--exec.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/exec.c b/exec.c
index be2a644619..f46e596818 100644
--- a/exec.c
+++ b/exec.c
@@ -1239,7 +1239,7 @@ static void *file_ram_alloc(RAMBlock *block,
char *sanitized_name;
char *c;
void *area;
- int fd;
+ int fd = -1;
int64_t page_size;
if (kvm_enabled() && !kvm_has_sync_mmu()) {
@@ -1321,7 +1321,6 @@ static void *file_ram_alloc(RAMBlock *block,
if (area == MAP_FAILED) {
error_setg_errno(errp, errno,
"unable to map backing store for guest RAM");
- close(fd);
goto error;
}
@@ -1336,7 +1335,9 @@ error:
if (unlink_on_error) {
unlink(path);
}
- close(fd);
+ if (fd != -1) {
+ close(fd);
+ }
return NULL;
}
#endif