提交 f4183068 编写于 作者: D Daniel P. Berrange

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: NDaniel P. Berrange <berrange@redhat.com>
上级 c2986ff0
......@@ -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);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册