]> xenbits.xensource.com Git - xen.git/commitdiff
x86: fix memory leak in pvh_setup_acpi_madt
authorWei Liu <wei.liu2@citrix.com>
Sun, 26 Feb 2017 15:49:31 +0000 (15:49 +0000)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Mon, 27 Feb 2017 11:26:28 +0000 (11:26 +0000)
Switch to use goto style error handling to avoid leaking madt.

Coverity-ID: 1401534

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
Reviewed-by: Roger Pau Monné <roger.pau@citrix.com>
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
xen/arch/x86/domain_build.c

index 0534838c8eaa807b08ec76f16aa16a60cc48ff0f..1f18f9283fc4a453b21627dc64bbd9f0e486a93a 100644 (file)
@@ -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,