[libvirt] [PATCH] cgroup: cleanup eventParams when virTypedParamsAddULLong failed

Michal Privoznik mprivozn at redhat.com
Thu Sep 19 13:58:56 UTC 2019


On 9/19/19 10:02 AM, Xu Yandong wrote:
> Function virTypedParamsAddULLong use realloc to gain memory,
> and doesn't free it when failed. so we need free eventParams to
> prevent a memory leak.
> 
> Signed-off-by: Xu Yandong <xuyandong2 at huawei.com>
> ---
>   src/qemu/qemu_cgroup.c | 5 ++++-
>   1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c
> index ecd96efb0a..bc498e4b10 100644
> --- a/src/qemu/qemu_cgroup.c
> +++ b/src/qemu/qemu_cgroup.c
> @@ -869,8 +869,11 @@ qemuSetupCpuCgroup(virDomainObjPtr vm)
>               if (virTypedParamsAddULLong(&eventParams, &eventNparams,
>                                           &eventMaxparams,
>                                           VIR_DOMAIN_TUNABLE_CPU_CPU_SHARES,
> -                                        val) < 0)
> +                                        val) < 0) {
> +                if (eventParams)

This check seems needless.

> +                    virTypedParamsFree(eventParams, eventNparams);
>                   return -1;
> +            }
>   
>               event = virDomainEventTunableNewFromObj(vm, eventParams, eventNparams);
>           }
> 


Have you actually seen a leak here or was this just found via code 
investigation?

Because the only way that virTypedParamsAddULLong() can fail is if 
VIR_RESIZE_N() called inside it fails at which point it doesn't allocate 
any new memory.

Michal




More information about the libvir-list mailing list