cpu: Cleanup ppcCompute to avoid memory leak

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

Signed-off-by: Li Zhang <zhlcindy@linux.vnet.ibm.com>
This commit is contained in:
Li Zhang 2013-09-09 13:56:33 +08:00 committed by John Ferlan
parent d047b2d983
commit 76fb8ccddf

View File

@ -354,7 +354,7 @@ ppcCompute(virCPUDefPtr host,
struct ppc_model *host_model = NULL; struct ppc_model *host_model = NULL;
struct ppc_model *guest_model = NULL; struct ppc_model *guest_model = NULL;
int ret = 0; virCPUCompareResult ret = VIR_CPU_COMPARE_ERROR;
virArch arch; virArch arch;
size_t i; size_t i;
@ -375,8 +375,10 @@ ppcCompute(virCPUDefPtr host,
virAsprintf(message, virAsprintf(message,
_("CPU arch %s does not match host arch"), _("CPU arch %s does not match host arch"),
virArchToString(cpu->arch)) < 0) virArchToString(cpu->arch)) < 0)
goto error; goto cleanup;
return VIR_CPU_COMPARE_INCOMPATIBLE;
ret = VIR_CPU_COMPARE_INCOMPATIBLE;
goto cleanup;
} }
arch = cpu->arch; arch = cpu->arch;
} else { } else {
@ -392,14 +394,16 @@ ppcCompute(virCPUDefPtr host,
_("host CPU vendor does not match required " _("host CPU vendor does not match required "
"CPU vendor %s"), "CPU vendor %s"),
cpu->vendor) < 0) cpu->vendor) < 0)
goto error; goto cleanup;
return VIR_CPU_COMPARE_INCOMPATIBLE;
ret = VIR_CPU_COMPARE_INCOMPATIBLE;
goto cleanup;
} }
if (!(map = ppcLoadMap()) || if (!(map = ppcLoadMap()) ||
!(host_model = ppcModelFromCPU(host, map)) || !(host_model = ppcModelFromCPU(host, map)) ||
!(guest_model = ppcModelFromCPU(cpu, map))) !(guest_model = ppcModelFromCPU(cpu, map)))
goto error; goto cleanup;
if (guestData != NULL) { if (guestData != NULL) {
if (cpu->type == VIR_CPU_TYPE_GUEST && if (cpu->type == VIR_CPU_TYPE_GUEST &&
@ -412,25 +416,23 @@ ppcCompute(virCPUDefPtr host,
_("host CPU model does not match required " _("host CPU model does not match required "
"CPU model %s"), "CPU model %s"),
guest_model->name) < 0) guest_model->name) < 0)
goto error; goto cleanup;
return VIR_CPU_COMPARE_INCOMPATIBLE;
ret = VIR_CPU_COMPARE_INCOMPATIBLE;
goto cleanup;
} }
if (!(*guestData = ppcMakeCPUData(arch, &guest_model->data))) if (!(*guestData = ppcMakeCPUData(arch, &guest_model->data)))
goto error; goto cleanup;
} }
ret = VIR_CPU_COMPARE_IDENTICAL; ret = VIR_CPU_COMPARE_IDENTICAL;
out: cleanup:
ppcMapFree(map); ppcMapFree(map);
ppcModelFree(host_model); ppcModelFree(host_model);
ppcModelFree(guest_model); ppcModelFree(guest_model);
return ret; return ret;
error:
ret = VIR_CPU_COMPARE_ERROR;
goto out;
} }
static virCPUCompareResult static virCPUCompareResult