From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54694) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1agpEt-0000a5-5s for qemu-devel@nongnu.org; Fri, 18 Mar 2016 03:54:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1agpEo-0007X0-6v for qemu-devel@nongnu.org; Fri, 18 Mar 2016 03:54:31 -0400 Received: from mx1.redhat.com ([209.132.183.28]:51740) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1agpEo-0007Wv-1K for qemu-devel@nongnu.org; Fri, 18 Mar 2016 03:54:26 -0400 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (Postfix) with ESMTPS id 25D7B4D6A9 for ; Fri, 18 Mar 2016 07:54:25 +0000 (UTC) References: <1458255068-11724-1-git-send-email-pbonzini@redhat.com> From: Laszlo Ersek Message-ID: <56EBB42F.4050506@redhat.com> Date: Fri, 18 Mar 2016 08:54:23 +0100 MIME-Version: 1.0 In-Reply-To: <1458255068-11724-1-git-send-email-pbonzini@redhat.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH] exec: fix error handling in file_ram_alloc List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Paolo Bonzini , qemu-devel@nongnu.org Cc: armbru@redhat.com On 03/17/16 23:51, Paolo Bonzini wrote: > 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 > Reviewed-by: Laszlo Ersek