All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Michael S. Tsirkin" <mst@redhat.com>
To: g00517791 <gaojinhao@huawei.com>
Cc: "Stefan Berger" <stefanb@linux.vnet.ibm.com>,
	"Jason Wang" <jasowang@redhat.com>,
	"Juan Quintela" <quintela@redhat.com>,
	qemu-devel@nongnu.org, "Greg Kurz" <groug@kaod.org>,
	qemu-ppc@nongnu.org, wanghaibin.wang@huawei.com,
	"Marc-André Lureau" <marcandre.lureau@redhat.com>,
	zhukeqian1@huawei.com,
	"Dr . David Alan Gilbert" <dgilbert@redhat.com>,
	"David Gibson" <david@gibson.dropbear.id.au>
Subject: Re: [PATCH 0/8] Fix memory leak of some device state in migration
Date: Sun, 27 Dec 2020 08:19:44 -0500	[thread overview]
Message-ID: <20201227081620-mutt-send-email-mst@kernel.org> (raw)
In-Reply-To: <20201226103347.868-1-gaojinhao@huawei.com>

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



  parent reply	other threads:[~2020-12-27 13:21 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-26 10:33 [PATCH 0/8] Fix memory leak of some device state in migration g00517791
2020-12-26 10:33 ` [PATCH 1/8] vmbus: Fix memory leak of vmstate_gpadl g00517791
2020-12-26 10:33 ` [PATCH 2/8] virtio-net: Fix memory leak of vmstate_virtio_net_rss g00517791
2020-12-26 10:33 ` [PATCH 3/8] spapr: Fix memory leak of vmstate_spapr_event_entry g00517791
2020-12-28  6:56   ` David Gibson
2020-12-26 10:33 ` [PATCH 4/8] spapr_pci: Fix memory leak of vmstate_spapr_pci g00517791
2020-12-28  6:58   ` David Gibson
2020-12-28  8:10     ` gaojinhao
2020-12-28  8:30       ` David Gibson
2020-12-28  9:31         ` gaojinhao
2020-12-26 10:33 ` [PATCH 5/8] savevm: Fix memory leak of vmstate_configuration g00517791
2020-12-26 10:33 ` [PATCH 6/8] vmbus: Fix memory leak of vmstate_vmbus_chan_req g00517791
2020-12-26 10:33 ` [PATCH 7/8] tpm_emulator: Fix memory leak of vmstate_tpm_emulator g00517791
2020-12-26 10:33 ` [PATCH 8/8] dbus-vmstate: Fix memory leak of dbus_vmstate g00517791
2020-12-26 16:39 ` [PATCH 0/8] Fix memory leak of some device state in migration no-reply
2020-12-27 13:19 ` Michael S. Tsirkin [this message]
2020-12-28  8:00   ` gaojinhao

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201227081620-mutt-send-email-mst@kernel.org \
    --to=mst@redhat.com \
    --cc=david@gibson.dropbear.id.au \
    --cc=dgilbert@redhat.com \
    --cc=gaojinhao@huawei.com \
    --cc=groug@kaod.org \
    --cc=jasowang@redhat.com \
    --cc=marcandre.lureau@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-ppc@nongnu.org \
    --cc=quintela@redhat.com \
    --cc=stefanb@linux.vnet.ibm.com \
    --cc=wanghaibin.wang@huawei.com \
    --cc=zhukeqian1@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.