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>
This commit is contained in:
Paolo Bonzini 2016-03-17 15:53:13 +01:00
parent 8526e1f4e4
commit 5c3ece79cd
1 changed files with 4 additions and 3 deletions

7
exec.c
View File

@ -1239,7 +1239,7 @@ static void *file_ram_alloc(RAMBlock *block,
char *sanitized_name; char *sanitized_name;
char *c; char *c;
void *area; void *area;
int fd; int fd = -1;
int64_t page_size; int64_t page_size;
if (kvm_enabled() && !kvm_has_sync_mmu()) { if (kvm_enabled() && !kvm_has_sync_mmu()) {
@ -1321,7 +1321,6 @@ static void *file_ram_alloc(RAMBlock *block,
if (area == MAP_FAILED) { if (area == MAP_FAILED) {
error_setg_errno(errp, errno, error_setg_errno(errp, errno,
"unable to map backing store for guest RAM"); "unable to map backing store for guest RAM");
close(fd);
goto error; goto error;
} }
@ -1336,7 +1335,9 @@ error:
if (unlink_on_error) { if (unlink_on_error) {
unlink(path); unlink(path);
} }
close(fd); if (fd != -1) {
close(fd);
}
return NULL; return NULL;
} }
#endif #endif