From: Wei Liu Date: Sun, 26 Feb 2017 15:49:31 +0000 (+0000) Subject: x86: fix memory leak in pvh_setup_acpi_madt X-Git-Tag: archive/raspbian/4.11.1-1+rpi1~1^2~66^2~2675 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=f597c3f307d73a874638619257c2040ec0139887;p=xen.git x86: fix memory leak in pvh_setup_acpi_madt Switch to use goto style error handling to avoid leaking madt. Coverity-ID: 1401534 Signed-off-by: Wei Liu Reviewed-by: Roger Pau Monné Reviewed-by: Andrew Cooper --- diff --git a/xen/arch/x86/domain_build.c b/xen/arch/x86/domain_build.c index 0534838c8e..1f18f9283f 100644 --- a/xen/arch/x86/domain_build.c +++ b/xen/arch/x86/domain_build.c @@ -2290,7 +2290,8 @@ static int __init pvh_setup_acpi_madt(struct domain *d, paddr_t *addr) if ( !madt ) { printk("Unable to allocate memory for MADT table\n"); - return -ENOMEM; + rc = -ENOMEM; + goto out; } /* Copy the native MADT table header. */ @@ -2298,7 +2299,8 @@ static int __init pvh_setup_acpi_madt(struct domain *d, paddr_t *addr) if ( !ACPI_SUCCESS(status) ) { printk("Failed to get MADT ACPI table, aborting.\n"); - return -EINVAL; + rc = -EINVAL; + goto out; } madt->header = *table; madt->address = APIC_DEFAULT_PHYS_BASE; @@ -2358,7 +2360,8 @@ static int __init pvh_setup_acpi_madt(struct domain *d, paddr_t *addr) if ( pvh_steal_ram(d, size, 0, GB(4), addr) ) { printk("Unable to find allocate guest RAM for MADT\n"); - return -ENOMEM; + rc = -ENOMEM; + goto out; } /* Mark this region as E820_ACPI. */ @@ -2369,11 +2372,15 @@ static int __init pvh_setup_acpi_madt(struct domain *d, paddr_t *addr) if ( rc ) { printk("Unable to copy MADT into guest memory\n"); - return rc; + goto out; } + + rc = 0; + + out: xfree(madt); - return 0; + return rc; } static bool __init acpi_memory_banned(unsigned long address,