From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33110) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aiN8B-0005IF-1c for qemu-devel@nongnu.org; Tue, 22 Mar 2016 10:18:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aiN8A-0006mJ-4e for qemu-devel@nongnu.org; Tue, 22 Mar 2016 10:17:58 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38055) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aiN89-0006mE-W5 for qemu-devel@nongnu.org; Tue, 22 Mar 2016 10:17:58 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (Postfix) with ESMTPS id B59CFC00B8EE for ; Tue, 22 Mar 2016 14:17:57 +0000 (UTC) Received: from donizetti.redhat.com (ovpn-112-37.ams2.redhat.com [10.36.112.37]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u2MEH9QF004983 for ; Tue, 22 Mar 2016 10:17:56 -0400 From: Paolo Bonzini Date: Tue, 22 Mar 2016 15:17:05 +0100 Message-Id: <1458656229-32043-26-git-send-email-pbonzini@redhat.com> In-Reply-To: <1458656229-32043-1-git-send-email-pbonzini@redhat.com> References: <1458656229-32043-1-git-send-email-pbonzini@redhat.com> Subject: [Qemu-devel] [PULL 25/29] 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 One instance of double closing, and invalid close(-1) in some cases of "goto error". Reviewed-by: Laszlo Ersek Signed-off-by: Paolo Bonzini --- exec.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/exec.c b/exec.c index be2a644..f46e596 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 -- 2.5.0