[libvirt] [PATCH 1/2] qemu: Fix leak in qemuProcessInitCpuAffinity()

John Ferlan jferlan at redhat.com
Thu Jun 6 10:44:29 UTC 2019



On 6/4/19 8:46 AM, Andrea Bolognani wrote:
> In two out of three scenarios we were cleaning up properly
> after ourselves, but in the remaining one we were leaking
> cpumapToSet.
> 
> Refactor the logic so that cpumapToSet is always a freshly
> allocated bitmap that gets cleaned up automatically thanks
> to VIR_AUTOPTR(); this also allows us to remove hostcpumap.
> 
> Reported-by: John Ferlan <jferlan at redhat.com>
> Signed-off-by: Andrea Bolognani <abologna at redhat.com>
> ---
>  src/qemu/qemu_process.c | 9 ++++-----
>  1 file changed, 4 insertions(+), 5 deletions(-)
> 
> diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
> index d44076288e..7d48c95973 100644
> --- a/src/qemu/qemu_process.c
> +++ b/src/qemu/qemu_process.c
> @@ -2464,8 +2464,7 @@ static int
>  qemuProcessInitCpuAffinity(virDomainObjPtr vm)
>  {
>      int ret = -1;
> -    virBitmapPtr cpumapToSet = NULL;
> -    VIR_AUTOPTR(virBitmap) hostcpumap = NULL;
> +    VIR_AUTOPTR(virBitmap) cpumapToSet = NULL;
>      virDomainNumatuneMemMode mem_mode;
>      qemuDomainObjPrivatePtr priv = vm->privateData;
>  
> @@ -2500,11 +2499,11 @@ qemuProcessInitCpuAffinity(virDomainObjPtr vm)
>          if (virNumaNodesetToCPUset(nodeset, &cpumapToSet) < 0)
>              goto cleanup;
>      } else if (vm->def->cputune.emulatorpin) {
> -        cpumapToSet = vm->def->cputune.emulatorpin;
> +        if (virBitmapCopy(cpumapToSet, vm->def->cputune.emulatorpin) < 0)

Now Coverity is unhappy for another reason.  What happens to the NULL
cpumapToSet when calling virBitmapCopy?

Should have been virBitmapNewCopy

John

(sorry didn't get a chance to look at the patch when first posted)

> +            goto cleanup;
>      } else {
> -        if (qemuProcessGetAllCpuAffinity(&hostcpumap) < 0)
> +        if (qemuProcessGetAllCpuAffinity(&cpumapToSet) < 0)
>              goto cleanup;
> -        cpumapToSet = hostcpumap;
>      }
>  
>      if (cpumapToSet &&
> 




More information about the libvir-list mailing list