[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 2/8] virtio-net: Fix memory leak of vmstate_virtio_net_rss
From: |
g00517791 |
Subject: |
[PATCH 2/8] virtio-net: Fix memory leak of vmstate_virtio_net_rss |
Date: |
Sat, 26 Dec 2020 18:33:41 +0800 |
From: Jinhao Gao <gaojinhao@huawei.com>
When VM migrate VMState of virtio-net-device/rss, the field(rss_data.
indirections_table) of virtio-net-device/rss having a flag of VMS_ALLOC
needs to allocate memory. If the dst doesn't free memory which has bee
n allocated for SaveStateEntry of virtio-net-device/rss before dst loads
device state, it may result that the pointer of rss_data.indirections_table
is overlaid when vm loads. We add the pre_load func to free memory, which
prevents memory leak.
Signed-off-by: Jinhao Gao <gaojinhao@huawei.com>
---
hw/net/virtio-net.c | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
index 044ac95f6f..102e51f32f 100644
--- a/hw/net/virtio-net.c
+++ b/hw/net/virtio-net.c
@@ -2957,11 +2957,22 @@ static bool virtio_net_rss_needed(void *opaque)
return VIRTIO_NET(opaque)->rss_data.enabled;
}
+static int virtio_net_rss_pre_load(void *opaque)
+{
+ VirtIONet *n = VIRTIO_NET(opaque);
+
+ g_free(n->rss_data.indirections_table);
+ n->rss_data.indirections_table = NULL;
+ n->rss_data.indirections_len = 0;
+ return 0;
+}
+
static const VMStateDescription vmstate_virtio_net_rss = {
.name = "virtio-net-device/rss",
.version_id = 1,
.minimum_version_id = 1,
.needed = virtio_net_rss_needed,
+ .pre_load = virtio_net_rss_pre_load,
.fields = (VMStateField[]) {
VMSTATE_BOOL(rss_data.enabled, VirtIONet),
VMSTATE_BOOL(rss_data.redirect, VirtIONet),
--
2.23.0
- [PATCH 0/8] Fix memory leak of some device state in migration, g00517791, 2020/12/26
- [PATCH 3/8] spapr: Fix memory leak of vmstate_spapr_event_entry, g00517791, 2020/12/26
- [PATCH 7/8] tpm_emulator: Fix memory leak of vmstate_tpm_emulator, g00517791, 2020/12/26
- [PATCH 8/8] dbus-vmstate: Fix memory leak of dbus_vmstate, g00517791, 2020/12/26
- [PATCH 2/8] virtio-net: Fix memory leak of vmstate_virtio_net_rss,
g00517791 <=
- [PATCH 6/8] vmbus: Fix memory leak of vmstate_vmbus_chan_req, g00517791, 2020/12/26
- [PATCH 1/8] vmbus: Fix memory leak of vmstate_gpadl, g00517791, 2020/12/26
- [PATCH 5/8] savevm: Fix memory leak of vmstate_configuration, g00517791, 2020/12/26
- [PATCH 4/8] spapr_pci: Fix memory leak of vmstate_spapr_pci, g00517791, 2020/12/26
Re: [PATCH 0/8] Fix memory leak of some device state in migration, no-reply, 2020/12/26
Re: [PATCH 0/8] Fix memory leak of some device state in migration, Michael S. Tsirkin, 2020/12/27