[libvirt PATCH 1/3] xenParseHypervisorFeatures: Fix memory leak

Peter Krempa pkrempa at redhat.com
Fri Apr 16 08:25:44 UTC 2021


On Thu, Apr 15, 2021 at 17:08:26 +0200, Tim Wiederhake wrote:

Fixes: b523e22521a

> Signed-off-by: Tim Wiederhake <twiederh at redhat.com>
> ---
>  src/libxl/xen_common.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/src/libxl/xen_common.c b/src/libxl/xen_common.c
> index 12a44280cb..ad5a3de116 100644
> --- a/src/libxl/xen_common.c
> +++ b/src/libxl/xen_common.c
> @@ -567,6 +567,7 @@ xenParseHypervisorFeatures(virConf *conf, virDomainDef *def)
>              timer->mode = VIR_DOMAIN_TIMER_MODE_PARAVIRT;
>  
>          def->clock.timers[def->clock.ntimers - 1] = timer;
> +        VIR_FREE(strval);

While this fixes the specific problem, it still leaves possibility for
making a mistake again since 'strval' isn't explicitly freed after the
second use.

A preferrable fix is to use one variable per use when used with
g_autofree or remove g_autofree and explicitly free it after both uses.

CCing Jim to state his preferred solution.

>      }
>  
>      if (xenConfigGetString(conf, "passthrough", &strval, NULL) < 0)
> -- 
> 2.26.2
> 




More information about the libvir-list mailing list