mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 17:34:18 +03:00
testUpdateQEMUCaps: Don't leak host cpuData
When preparing qemuCaps for test cases the following is happening: qemuTestParseCapabilitiesArch() is called, which calls virQEMUCapsLoadCache() which in turn calls virQEMUCapsInitHostCPUModel() which sets qemuCaps->kvmCPU and qemuCaps->tcgCPU. But then the code tries to update the capabilities: testCompareXMLToArgv() calls testUpdateQEMUCaps() which calls virQEMUCapsInitHostCPUModel() again overwriting previously allocated memory. The solution is to free host cpuData in testUpdateQEMUCaps(). Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
This commit is contained in:
parent
cc9c75f562
commit
5276ec712a
@ -1516,12 +1516,19 @@ virQEMUCapsHostCPUDataCopy(virQEMUCapsHostCPUDataPtr dst,
|
||||
|
||||
|
||||
static void
|
||||
virQEMUCapsHostCPUDataClear(virQEMUCapsHostCPUDataPtr cpuData)
|
||||
virQEMUCapsHostCPUDataClearModels(virQEMUCapsHostCPUDataPtr cpuData)
|
||||
{
|
||||
qemuMonitorCPUModelInfoFree(cpuData->info);
|
||||
virCPUDefFree(cpuData->reported);
|
||||
virCPUDefFree(cpuData->migratable);
|
||||
virCPUDefFree(cpuData->full);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
virQEMUCapsHostCPUDataClear(virQEMUCapsHostCPUDataPtr cpuData)
|
||||
{
|
||||
qemuMonitorCPUModelInfoFree(cpuData->info);
|
||||
virQEMUCapsHostCPUDataClearModels(cpuData);
|
||||
|
||||
memset(cpuData, 0, sizeof(*cpuData));
|
||||
}
|
||||
@ -2834,6 +2841,16 @@ virQEMUCapsNewHostCPUModel(void)
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
virQEMUCapsFreeHostCPUModel(virQEMUCapsPtr qemuCaps,
|
||||
virDomainVirtType type)
|
||||
{
|
||||
virQEMUCapsHostCPUDataPtr cpuData = virQEMUCapsGetHostCPUData(qemuCaps, type);
|
||||
|
||||
virQEMUCapsHostCPUDataClearModels(cpuData);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
virQEMUCapsInitHostCPUModel(virQEMUCapsPtr qemuCaps,
|
||||
virArch hostArch,
|
||||
|
@ -56,6 +56,10 @@ void
|
||||
virQEMUCapsSetArch(virQEMUCapsPtr qemuCaps,
|
||||
virArch arch);
|
||||
|
||||
void
|
||||
virQEMUCapsFreeHostCPUModel(virQEMUCapsPtr qemuCaps,
|
||||
virDomainVirtType type);
|
||||
|
||||
void
|
||||
virQEMUCapsInitHostCPUModel(virQEMUCapsPtr qemuCaps,
|
||||
virArch hostArch,
|
||||
|
@ -388,6 +388,9 @@ testUpdateQEMUCaps(const struct testInfo *info,
|
||||
if (testAddCPUModels(info->qemuCaps, info->skipLegacyCPUs) < 0)
|
||||
goto cleanup;
|
||||
|
||||
virQEMUCapsFreeHostCPUModel(info->qemuCaps, VIR_DOMAIN_VIRT_KVM);
|
||||
virQEMUCapsFreeHostCPUModel(info->qemuCaps, VIR_DOMAIN_VIRT_QEMU);
|
||||
|
||||
virQEMUCapsInitHostCPUModel(info->qemuCaps, caps->host.arch,
|
||||
VIR_DOMAIN_VIRT_KVM);
|
||||
virQEMUCapsInitHostCPUModel(info->qemuCaps, caps->host.arch,
|
||||
|
Loading…
Reference in New Issue
Block a user