[libvirt] [PATCH] testUpdateQEMUCaps: Don't leak host cpuData

Jiri Denemark jdenemar at redhat.com
Thu May 31 12:10:28 UTC 2018


On Thu, May 31, 2018 at 12:11:36 +0200, Michal Privoznik wrote:
> 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 at redhat.com>
> ---
> 
> Technically this is v2 of [1] but since it implements completely
> different approach I'm sending it as v1.
> 
> 1: https://www.redhat.com/archives/libvir-list/2018-May/msg02260.html
> 
>  src/qemu/qemu_capabilities.c | 21 +++++++++++++++++++--
>  src/qemu/qemu_capspriv.h     |  4 ++++
>  tests/qemuxml2argvtest.c     |  3 +++
>  3 files changed, 26 insertions(+), 2 deletions(-)
> 
> diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
> index e2e76e4dd8..ea1ff520d8 100644
> --- a/src/qemu/qemu_capabilities.c
> +++ b/src/qemu/qemu_capabilities.c
> @@ -1516,12 +1516,19 @@ virQEMUCapsHostCPUDataCopy(virQEMUCapsHostCPUDataPtr dst,
>  
>  
>  static void
> -virQEMUCapsHostCPUDataClear(virQEMUCapsHostCPUDataPtr cpuData)
> +virQEMUCapsHostCPUDataClearHostCPU(virQEMUCapsHostCPUDataPtr cpuData)

The name is weired with two HostCPU substrings. How about

    virQEMUCapsHostCPUDataClearModels

as it frees the generated CPU models, or

    virQEMUCapsHostCPUDataClearGenerated

to emphasize the function clears the CPU models generated from other
data which we store in the cache?

>  {
> -    qemuMonitorCPUModelInfoFree(cpuData->info);
>      virCPUDefFree(cpuData->reported);
>      virCPUDefFree(cpuData->migratable);
>      virCPUDefFree(cpuData->full);
> +}
> +
> +
> +static void
> +virQEMUCapsHostCPUDataClear(virQEMUCapsHostCPUDataPtr cpuData)
> +{
> +    qemuMonitorCPUModelInfoFree(cpuData->info);
> +    virQEMUCapsHostCPUDataClearHostCPU(cpuData);

And this would need to be changed too, of course.

>  
>      memset(cpuData, 0, sizeof(*cpuData));
>  }

With the changed name

Reviewed-by: Jiri Denemark <jdenemar at redhat.com>




More information about the libvir-list mailing list