qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [PATCH 0/8] Fix memory leak of some device state in migration


From: gaojinhao
Subject: RE: [PATCH 0/8] Fix memory leak of some device state in migration
Date: Mon, 28 Dec 2020 08:00:16 +0000

Thank you for you review. I will modify patches according to your opinion.

Jinhao Gao

-----Original Message-----
From: Michael S. Tsirkin [mailto:mst@redhat.com] 
Sent: 2020年12月27日 21:20
To: gaojinhao <gaojinhao@huawei.com>
Cc: qemu-devel@nongnu.org; qemu-ppc@nongnu.org; Marc-André Lureau 
<marcandre.lureau@redhat.com>; Stefan Berger <stefanb@linux.vnet.ibm.com>; 
Jason Wang <jasowang@redhat.com>; David Gibson <david@gibson.dropbear.id.au>; 
Greg Kurz <groug@kaod.org>; Juan Quintela <quintela@redhat.com>; Dr . David 
Alan Gilbert <dgilbert@redhat.com>; Wanghaibin (D) 
<wanghaibin.wang@huawei.com>; zhukeqian <zhukeqian1@huawei.com>
Subject: Re: [PATCH 0/8] Fix memory leak of some device state in migration

On Sat, Dec 26, 2020 at 06:33:39PM +0800, g00517791 wrote:
> From: Jinhao Gao <gaojinhao@huawei.com>
> 
> For some device state having some fields of VMS_ALLOC flag, they don't 
> free memory allocated for the fields in vmstate_save_state and vmstate 
> _load_state. We add funcs or sentences of free memory before 
> allocation of memory or after load of memory to avoid memory leak.
> 

Isn't there a way to handle it centrally?
IIUC the issue is repeated loads in case a load fails, right?
So can't we do something along the lines of:

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>

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);
         }
     }

--
MST


reply via email to

[Prev in Thread] Current Thread [Next in Thread]