Thank you for review!

Jinhao Gao

-----Original Message-----
From: Dr. David Alan Gilbert [mailto:[email protected]] 
Sent: 2021年1月5日 19:18
To: gaojinhao <[email protected]>
Cc: [email protected]; [email protected]; Michael S . Tsirkin 
<[email protected]>; David Gibson <[email protected]>; Greg Kurz 
<[email protected]>; Marc-André Lureau <[email protected]>; Stefan 
Berger <[email protected]>; Jason Wang <[email protected]>; Juan 
Quintela <[email protected]>; Wanghaibin (D) <[email protected]>; 
zhukeqian <[email protected]>
Subject: Re: [PATCH v3 3/3] vmstate: Fix memory leak in vmstate_handle_alloc()

* Jinhao Gao ([email protected]) wrote:
> Some memory allocated for fields having a flag of VMS_ALLOC in 
> SaveState may not free before VM load vmsd in migration. So we 
> pre-free memory before allocation in vmstate_handle_alloc() to avoid memleaks.
> 
> Reported-by: Euler Robot <[email protected]>
> Signed-off-by: Jinhao Gao <[email protected]>
> Signed-off-by: Michael S. Tsirkin <[email protected]>

Yes, I think that's OK; it's actually pretty rare for this to happen; normally 
inwards migrations either succeed or fail and exit; doing multiple loads from 
snapshots is valid and I guess COLO hits this as well.

Reviewed-by: Dr. David Alan Gilbert <[email protected]>

> ---
>  migration/vmstate.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/migration/vmstate.c b/migration/vmstate.c index 
> e9d2aef66b..873f76739f 100644
> --- a/migration/vmstate.c
> +++ b/migration/vmstate.c
> @@ -70,6 +70,7 @@ static void vmstate_handle_alloc(void *ptr, const 
> VMStateField *field,
>          gsize size = vmstate_size(opaque, field);
>          size *= vmstate_n_elems(opaque, field);
>          if (size) {
> +            g_free(*(void **)ptr);
>              *(void **)ptr = g_malloc(size);
>          }
>      }
> --
> 2.23.0
> 
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

Reply via email to