From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47531) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1agglA-0005m5-W0 for qemu-devel@nongnu.org; Thu, 17 Mar 2016 18:51:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aggl7-0000Px-Q4 for qemu-devel@nongnu.org; Thu, 17 Mar 2016 18:51:16 -0400 Received: from mail-wm0-x235.google.com ([2a00:1450:400c:c09::235]:35340) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aggl7-0000Pl-JY for qemu-devel@nongnu.org; Thu, 17 Mar 2016 18:51:13 -0400 Received: by mail-wm0-x235.google.com with SMTP id l68so11874192wml.0 for ; Thu, 17 Mar 2016 15:51:13 -0700 (PDT) Sender: Paolo Bonzini From: Paolo Bonzini Date: Thu, 17 Mar 2016 23:51:08 +0100 Message-Id: <1458255068-11724-1-git-send-email-pbonzini@redhat.com> Subject: [Qemu-devel] [PATCH] exec: fix error handling in file_ram_alloc List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: armbru@redhat.com One instance of double closing, and invalid close(-1) in some cases of "goto error". Signed-off-by: Paolo Bonzini --- exec.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/exec.c b/exec.c index f398d21..5c16f41 100644 --- a/exec.c +++ b/exec.c @@ -1238,7 +1238,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()) { @@ -1320,7 +1320,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; } @@ -1335,7 +1334,9 @@ error: if (unlink_on_error) { unlink(path); } - close(fd); + if (fd != -1) { + close(fd); + } return NULL; } #endif -- 2.5.0