From patchwork Sun Feb 26 15:49:32 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Wei Liu X-Patchwork-Id: 9592297 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 9B1F160574 for ; Sun, 26 Feb 2017 15:52:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8C0F127FB0 for ; Sun, 26 Feb 2017 15:52:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 756202845E; Sun, 26 Feb 2017 15:52:07 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id EBF2927FB0 for ; Sun, 26 Feb 2017 15:52:05 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ci14u-0008Nz-GN; Sun, 26 Feb 2017 15:49:40 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ci14t-0008Nt-37 for xen-devel@lists.xenproject.org; Sun, 26 Feb 2017 15:49:39 +0000 Received: from [85.158.137.68] by server-2.bemta-3.messagelabs.com id A0/47-16699-219F2B85; Sun, 26 Feb 2017 15:49:38 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmpmkeJIrShJLcpLzFFi42JxWrohUlfw56Y IgyVNmhbft0xmcmD0OPzhCksAYxRrZl5SfkUCa8bH/oUsBasFKl5NO8zSwDiBp4uRg0NCwF/i 9zKtLkZODjYBZYmfnb1sILaIgJ5E04HnjF2MXBzMAmsYJVom/GYBSQgLOEj8PDmfDaSXRUBV4 sdeVZAwr4CFxIL3IPWcQCPlJXa1XWQFKeEUsJS4sTkIJCwEVNJ7azsrhK0g0TH9GBNEq6DEyZ lPwKYzC0hIHHzxgnkCI+8sJKlZSFILGJlWMWoUpxaVpRbpGpnqJRVlpmeU5CZm5ugaGhjr5aY WFyemp+YkJhXrJefnbmIEBk49AwPjDsbWE36HGCU5mJREeRcZb4wQ4kvKT6nMSCzOiC8qzUkt PsQow8GhJMEb8WNThJBgUWp6akVaZg4whGHSEhw8SiK8tZ+B0rzFBYm5xZnpEKlTjIpS4rxPv gMlBEASGaV5cG2wuLnEKCslzMvIwMAgxFOQWpSbWYIq/4pRnINRSZjXFWQ7T2ZeCdz0V0CLmY AWzwa5mbe4JBEhJdXAKNTa6q1lZyGS3cDq6bBo8trIOzOCrnQ9lWTlYTHU3P8s7tGCuQUWH/2 eKda9nJlu+WmJq9KSldbKLUccZtcuur2Q72FN8irZSRZH1pRct/kVcOWY/JL9bYHXmr/zT0xc kqVyMjtMwz5qVi//x0oN9a6T+k/W6gVoedTcnztTMkQ/IXJ7krOEEktxRqKhFnNRcSIAJy4wI 5YCAAA= X-Env-Sender: prvs=22314941b=wei.liu2@citrix.com X-Msg-Ref: server-4.tower-31.messagelabs.com!1488124176!29405397!1 X-Originating-IP: [66.165.176.89] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni44OSA9PiAyMDMwMDc=\n, received_headers: No Received headers X-StarScan-Received: X-StarScan-Version: 9.2.3; banners=-,-,- X-VirusChecked: Checked Received: (qmail 13706 invoked from network); 26 Feb 2017 15:49:37 -0000 Received: from smtp.citrix.com (HELO SMTP.CITRIX.COM) (66.165.176.89) by server-4.tower-31.messagelabs.com with RC4-SHA encrypted SMTP; 26 Feb 2017 15:49:37 -0000 X-IronPort-AV: E=Sophos;i="5.35,209,1484006400"; d="scan'208";a="409832555" From: Wei Liu To: Xen-devel Date: Sun, 26 Feb 2017 15:49:32 +0000 Message-ID: <20170226154932.30401-3-wei.liu2@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170226154932.30401-1-wei.liu2@citrix.com> References: <20170226154932.30401-1-wei.liu2@citrix.com> MIME-Version: 1.0 Cc: Andrew Cooper , Wei Liu , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Subject: [Xen-devel] [PATCH 2/2] x86: fix memory leak in pvh_setup_acpi_xsdt X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP Switch to use goto style error handling to avoid leaking xsdt. Coverity-ID: 1401535 Signed-off-by: Wei Liu Reviewed-by: Roger Pau Monné --- xen/arch/x86/domain_build.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/xen/arch/x86/domain_build.c b/xen/arch/x86/domain_build.c index 1f18f9283f..d74296509a 100644 --- a/xen/arch/x86/domain_build.c +++ b/xen/arch/x86/domain_build.c @@ -2459,7 +2459,8 @@ static int __init pvh_setup_acpi_xsdt(struct domain *d, paddr_t madt_addr, if ( !xsdt ) { printk("Unable to allocate memory for XSDT table\n"); - return -ENOMEM; + rc = -ENOMEM; + goto out; } /* Copy the native XSDT table header. */ @@ -2467,7 +2468,8 @@ static int __init pvh_setup_acpi_xsdt(struct domain *d, paddr_t madt_addr, if ( !rsdp ) { printk("Unable to map RSDP\n"); - return -EINVAL; + rc = -EINVAL; + goto out; } xsdt_paddr = rsdp->xsdt_physical_address; acpi_os_unmap_memory(rsdp, sizeof(*rsdp)); @@ -2475,7 +2477,8 @@ static int __init pvh_setup_acpi_xsdt(struct domain *d, paddr_t madt_addr, if ( !table ) { printk("Unable to map XSDT\n"); - return -EINVAL; + rc = -EINVAL; + goto out; } xsdt->header = *table; acpi_os_unmap_memory(table, sizeof(*table)); @@ -2505,7 +2508,8 @@ static int __init pvh_setup_acpi_xsdt(struct domain *d, paddr_t madt_addr, if ( pvh_steal_ram(d, size, 0, GB(4), addr) ) { printk("Unable to find guest RAM for XSDT\n"); - return -ENOMEM; + rc = -ENOMEM; + goto out; } /* Mark this region as E820_ACPI. */ @@ -2516,11 +2520,15 @@ static int __init pvh_setup_acpi_xsdt(struct domain *d, paddr_t madt_addr, if ( rc ) { printk("Unable to copy XSDT into guest memory\n"); - return rc; + goto out; } + + rc = 0; + + out: xfree(xsdt); - return 0; + return rc; } static int __init pvh_setup_acpi(struct domain *d, paddr_t start_info)