OSDN Git Service

exec: fix error handling in file_ram_alloc
authorPaolo Bonzini <pbonzini@redhat.com>
Thu, 17 Mar 2016 14:53:13 +0000 (15:53 +0100)
committerPaolo Bonzini <pbonzini@redhat.com>
Tue, 22 Mar 2016 21:20:18 +0000 (22:20 +0100)
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>
exec.c

diff --git a/exec.c b/exec.c
index be2a644..f46e596 100644 (file)
--- 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