From patchwork Thu Mar 17 22:51:08 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 8614981 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 55998C0553 for ; Thu, 17 Mar 2016 22:58:50 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id BB69C20218 for ; Thu, 17 Mar 2016 22:58:49 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 1FF7B20212 for ; Thu, 17 Mar 2016 22:58:49 +0000 (UTC) Received: from localhost ([::1]:40473 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aggsS-0003Mm-L6 for patchwork-qemu-devel@patchwork.kernel.org; Thu, 17 Mar 2016 18:58:48 -0400 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) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id; bh=hkHRPanBNHIGYaT1XO7XCfP8+c0P/Ii6m12ielQOtNM=; b=RfjoTh+t8rUlsiCbH4xdZIkeDPlFqrvEYwyQeMwBbauXQPH2dJfidPW4C0udXijOUW Q6GuHJITnHbqcaf+uw+Pdd/cT6I5ckGcoBF7q/NnTWKKqHoMbOfPMK/DG5z0WisHmMOK ciGC6lQOTctSaAVbuxOmErdcAp1W+f9Tga1/7IOiou9Q+vpuUN+amlRtB36CnOcrx+K8 UBLUuBOkJGJ0CbV3hs/Y/WaYzkvqTvaRFhAAQ8VSBJML7hB4I5H6h+QQjjs/5O6PjnPR 4nory/8/oXzDRbxT/rDWwINX8SX3xbBSOxB4zgpntNZtdF5FKi+MiBqLXoxejDel0r/z tqcA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id; bh=hkHRPanBNHIGYaT1XO7XCfP8+c0P/Ii6m12ielQOtNM=; b=gCVez2bRgFJlebQJR+rYH9tugBt0m1d/Ybw7aWEcP3hxuVSxIP2Ebb1yqz2ixeB5yF 8ml94+w+9008LY7FUF4JzxFk6NayCRIqdsE6YRxSkdo30uDI7Xv0nDfg7utwkyuyDZa0 j7bnQUw0W+fdsz94nB3+sVBRIwRVqTUSIFv/nJxzEO2xLKYm7XX6PkWu9ifAjl6hqpdC 20msTTyDOl1Hr8VaOCBos+mhNjy5wfr8qAEMqSuvdVAobzqwwe2TedXdxjqV2VHob957 mpxpdtYI2cHAHOEcX+dQY3VLjOb178oYIVYQvke7qslxHyHMNxfch5dtZIDgx1df3L4n yMPQ== X-Gm-Message-State: AD7BkJLLK14Ms4Cd5kvvDEwCROeHcsODyHs8FR4bgyR3d8lYmdluowajiDhIoaEkY5CUbA== X-Received: by 10.28.111.12 with SMTP id k12mr12969258wmc.35.1458255072900; Thu, 17 Mar 2016 15:51:12 -0700 (PDT) Received: from donizetti.lan (94-39-161-17.adsl-ull.clienti.tiscali.it. [94.39.161.17]) by smtp.gmail.com with ESMTPSA id t3sm9648194wjz.11.2016.03.17.15.51.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 17 Mar 2016 15:51:12 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 17 Mar 2016 23:51:08 +0100 Message-Id: <1458255068-11724-1-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 2.5.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::235 Cc: armbru@redhat.com Subject: [Qemu-devel] [PATCH] exec: fix error handling in file_ram_alloc X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP One instance of double closing, and invalid close(-1) in some cases of "goto error". Signed-off-by: Paolo Bonzini Reviewed-by: Laszlo Ersek --- 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