mirror of https://gitee.com/openkylin/libvirt.git
Fix mem leak in virQEMUCapsProbeQMPMachineTypes on OOM
The virQEMUCapsProbeQMPMachineTypes method iterates over machine types copying them into the qemuCapsPtr object. It only updates the qemuCaps->nmachinetypes value at the end though. So if OOM occurs in the middle, the destructor of qemuCapsPtr will not free the partially initialized machine types. Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
This commit is contained in:
parent
c2986ff0d3
commit
f41830680e
|
@ -2137,14 +2137,17 @@ virQEMUCapsProbeQMPMachineTypes(virQEMUCapsPtr qemuCaps,
|
|||
goto cleanup;
|
||||
|
||||
for (i = 0; i < nmachines; i++) {
|
||||
if (VIR_STRDUP(qemuCaps->machineAliases[i], machines[i]->alias) < 0 ||
|
||||
VIR_STRDUP(qemuCaps->machineTypes[i], machines[i]->name) < 0)
|
||||
qemuCaps->nmachineTypes++;
|
||||
if (VIR_STRDUP(qemuCaps->machineAliases[qemuCaps->nmachineTypes -1],
|
||||
machines[i]->alias) < 0 ||
|
||||
VIR_STRDUP(qemuCaps->machineTypes[qemuCaps->nmachineTypes - 1],
|
||||
machines[i]->name) < 0)
|
||||
goto cleanup;
|
||||
if (machines[i]->isDefault)
|
||||
defIdx = i;
|
||||
qemuCaps->machineMaxCpus[i] = machines[i]->maxCpus;
|
||||
qemuCaps->machineMaxCpus[qemuCaps->nmachineTypes - 1] =
|
||||
machines[i]->maxCpus;
|
||||
}
|
||||
qemuCaps->nmachineTypes = nmachines;
|
||||
|
||||
if (defIdx)
|
||||
virQEMUCapsSetDefaultMachine(qemuCaps, defIdx);
|
||||
|
|
Loading…
Reference in New Issue