[libvirt] [PATCH 1/1] cpu: Cleanup ppcCompute to avoid memory leak

Li Zhang zhlcindy at gmail.com
Mon Sep 9 05:56:33 UTC 2013


From: Li Zhang <zhlcindy at linux.vnet.ibm.com>

This patch is to Cleanup ppcCompute to avoid memory leak to make
the code better.

Signed-off-by: Li Zhang <zhlcindy at linux.vnet.ibm.com>
---
 src/cpu/cpu_powerpc.c | 36 +++++++++++++++++++-----------------
 1 file changed, 19 insertions(+), 17 deletions(-)

diff --git a/src/cpu/cpu_powerpc.c b/src/cpu/cpu_powerpc.c
index a47ee38..4e90672 100644
--- a/src/cpu/cpu_powerpc.c
+++ b/src/cpu/cpu_powerpc.c
@@ -345,16 +345,16 @@ ppcMakeCPUData(virArch arch, struct cpuPPCData *data)
 
 static virCPUCompareResult
 ppcCompute(virCPUDefPtr host,
-             const virCPUDefPtr cpu,
-             virCPUDataPtr *guestData,
-             char **message)
+           const virCPUDefPtr cpu,
+           virCPUDataPtr *guestData,
+           char **message)
 
 {
     struct ppc_map *map = NULL;
     struct ppc_model *host_model = NULL;
     struct ppc_model *guest_model = NULL;
 
-    int ret = 0;
+    virCPUCompareResult ret = VIR_CPU_COMPARE_ERROR;
     virArch arch;
     size_t i;
 
@@ -375,8 +375,10 @@ ppcCompute(virCPUDefPtr host,
                 virAsprintf(message,
                             _("CPU arch %s does not match host arch"),
                             virArchToString(cpu->arch)) < 0)
-                goto error;
-            return VIR_CPU_COMPARE_INCOMPATIBLE;
+                goto cleanup;
+
+            ret = VIR_CPU_COMPARE_INCOMPATIBLE;
+            goto cleanup;
         }
         arch = cpu->arch;
     } else {
@@ -392,14 +394,16 @@ ppcCompute(virCPUDefPtr host,
                         _("host CPU vendor does not match required "
                         "CPU vendor %s"),
                         cpu->vendor) < 0)
-            goto error;
-        return VIR_CPU_COMPARE_INCOMPATIBLE;
+            goto cleanup;
+
+        ret = VIR_CPU_COMPARE_INCOMPATIBLE;
+        goto cleanup;
     }
 
     if (!(map = ppcLoadMap()) ||
         !(host_model = ppcModelFromCPU(host, map)) ||
         !(guest_model = ppcModelFromCPU(cpu, map)))
-        goto error;
+        goto cleanup;
 
     if (guestData != NULL) {
         if (cpu->type == VIR_CPU_TYPE_GUEST &&
@@ -412,25 +416,23 @@ ppcCompute(virCPUDefPtr host,
                             _("host CPU model does not match required "
                             "CPU model %s"),
                             guest_model->name) < 0)
-                goto error;
-            return VIR_CPU_COMPARE_INCOMPATIBLE;
+                goto cleanup;
+
+            ret = VIR_CPU_COMPARE_INCOMPATIBLE;
+            goto cleanup;
         }
 
         if (!(*guestData = ppcMakeCPUData(arch, &guest_model->data)))
-            goto error;
+            goto cleanup;
     }
 
     ret = VIR_CPU_COMPARE_IDENTICAL;
 
-out:
+cleanup:
     ppcMapFree(map);
     ppcModelFree(host_model);
     ppcModelFree(guest_model);
     return ret;
-
-error:
-    ret = VIR_CPU_COMPARE_ERROR;
-    goto out;
 }
 
 static virCPUCompareResult
-- 
1.8.1.4




More information about the libvir-list mailing list