qemu_capabilities: Resolve Coverity RESOURCE_LEAK

Coverity determined that on error path that 'mach' wouldn't be free'd
Since virCapabilitiesFreeGuestMachine() isn't globally available, we'll
insert first and then if the VIR_STRDUP's fail they it will eventually
cause the 'mach' to be freed in the error path
This commit is contained in:
John Ferlan 2014-08-27 14:57:08 -04:00
parent 2cc03c8050
commit 2f7ced36e6
1 changed files with 1 additions and 1 deletions

View File

@ -2108,6 +2108,7 @@ int virQEMUCapsGetMachineTypesCaps(virQEMUCapsPtr qemuCaps,
virCapsGuestMachinePtr mach; virCapsGuestMachinePtr mach;
if (VIR_ALLOC(mach) < 0) if (VIR_ALLOC(mach) < 0)
goto error; goto error;
(*machines)[i] = mach;
if (qemuCaps->machineAliases[i]) { if (qemuCaps->machineAliases[i]) {
if (VIR_STRDUP(mach->name, qemuCaps->machineAliases[i]) < 0 || if (VIR_STRDUP(mach->name, qemuCaps->machineAliases[i]) < 0 ||
VIR_STRDUP(mach->canonical, qemuCaps->machineTypes[i]) < 0) VIR_STRDUP(mach->canonical, qemuCaps->machineTypes[i]) < 0)
@ -2117,7 +2118,6 @@ int virQEMUCapsGetMachineTypesCaps(virQEMUCapsPtr qemuCaps,
goto error; goto error;
} }
mach->maxCpus = qemuCaps->machineMaxCpus[i]; mach->maxCpus = qemuCaps->machineMaxCpus[i];
(*machines)[i] = mach;
} }
return 0; return 0;