mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-01 06:27:16 +00:00
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;
|
goto cleanup;
|
||||||
|
|
||||||
for (i = 0; i < nmachines; i++) {
|
for (i = 0; i < nmachines; i++) {
|
||||||
if (VIR_STRDUP(qemuCaps->machineAliases[i], machines[i]->alias) < 0 ||
|
qemuCaps->nmachineTypes++;
|
||||||
VIR_STRDUP(qemuCaps->machineTypes[i], machines[i]->name) < 0)
|
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;
|
goto cleanup;
|
||||||
if (machines[i]->isDefault)
|
if (machines[i]->isDefault)
|
||||||
defIdx = i;
|
defIdx = i;
|
||||||
qemuCaps->machineMaxCpus[i] = machines[i]->maxCpus;
|
qemuCaps->machineMaxCpus[qemuCaps->nmachineTypes - 1] =
|
||||||
|
machines[i]->maxCpus;
|
||||||
}
|
}
|
||||||
qemuCaps->nmachineTypes = nmachines;
|
|
||||||
|
|
||||||
if (defIdx)
|
if (defIdx)
|
||||||
virQEMUCapsSetDefaultMachine(qemuCaps, defIdx);
|
virQEMUCapsSetDefaultMachine(qemuCaps, defIdx);
|
||||||
|
Loading…
Reference in New Issue
Block a user