提交 5276ec71 编写于 作者: M Michal Privoznik

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: NMichal Privoznik <mprivozn@redhat.com>
Reviewed-by: NJiri Denemark <jdenemar@redhat.com>
上级 cc9c75f5
...@@ -1516,12 +1516,19 @@ virQEMUCapsHostCPUDataCopy(virQEMUCapsHostCPUDataPtr dst, ...@@ -1516,12 +1516,19 @@ virQEMUCapsHostCPUDataCopy(virQEMUCapsHostCPUDataPtr dst,
static void static void
virQEMUCapsHostCPUDataClear(virQEMUCapsHostCPUDataPtr cpuData) virQEMUCapsHostCPUDataClearModels(virQEMUCapsHostCPUDataPtr cpuData)
{ {
qemuMonitorCPUModelInfoFree(cpuData->info);
virCPUDefFree(cpuData->reported); virCPUDefFree(cpuData->reported);
virCPUDefFree(cpuData->migratable); virCPUDefFree(cpuData->migratable);
virCPUDefFree(cpuData->full); virCPUDefFree(cpuData->full);
}
static void
virQEMUCapsHostCPUDataClear(virQEMUCapsHostCPUDataPtr cpuData)
{
qemuMonitorCPUModelInfoFree(cpuData->info);
virQEMUCapsHostCPUDataClearModels(cpuData);
memset(cpuData, 0, sizeof(*cpuData)); memset(cpuData, 0, sizeof(*cpuData));
} }
...@@ -2834,6 +2841,16 @@ virQEMUCapsNewHostCPUModel(void) ...@@ -2834,6 +2841,16 @@ virQEMUCapsNewHostCPUModel(void)
} }
void
virQEMUCapsFreeHostCPUModel(virQEMUCapsPtr qemuCaps,
virDomainVirtType type)
{
virQEMUCapsHostCPUDataPtr cpuData = virQEMUCapsGetHostCPUData(qemuCaps, type);
virQEMUCapsHostCPUDataClearModels(cpuData);
}
void void
virQEMUCapsInitHostCPUModel(virQEMUCapsPtr qemuCaps, virQEMUCapsInitHostCPUModel(virQEMUCapsPtr qemuCaps,
virArch hostArch, virArch hostArch,
......
...@@ -56,6 +56,10 @@ void ...@@ -56,6 +56,10 @@ void
virQEMUCapsSetArch(virQEMUCapsPtr qemuCaps, virQEMUCapsSetArch(virQEMUCapsPtr qemuCaps,
virArch arch); virArch arch);
void
virQEMUCapsFreeHostCPUModel(virQEMUCapsPtr qemuCaps,
virDomainVirtType type);
void void
virQEMUCapsInitHostCPUModel(virQEMUCapsPtr qemuCaps, virQEMUCapsInitHostCPUModel(virQEMUCapsPtr qemuCaps,
virArch hostArch, virArch hostArch,
......
...@@ -388,6 +388,9 @@ testUpdateQEMUCaps(const struct testInfo *info, ...@@ -388,6 +388,9 @@ testUpdateQEMUCaps(const struct testInfo *info,
if (testAddCPUModels(info->qemuCaps, info->skipLegacyCPUs) < 0) if (testAddCPUModels(info->qemuCaps, info->skipLegacyCPUs) < 0)
goto cleanup; goto cleanup;
virQEMUCapsFreeHostCPUModel(info->qemuCaps, VIR_DOMAIN_VIRT_KVM);
virQEMUCapsFreeHostCPUModel(info->qemuCaps, VIR_DOMAIN_VIRT_QEMU);
virQEMUCapsInitHostCPUModel(info->qemuCaps, caps->host.arch, virQEMUCapsInitHostCPUModel(info->qemuCaps, caps->host.arch,
VIR_DOMAIN_VIRT_KVM); VIR_DOMAIN_VIRT_KVM);
virQEMUCapsInitHostCPUModel(info->qemuCaps, caps->host.arch, virQEMUCapsInitHostCPUModel(info->qemuCaps, caps->host.arch,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册