diff mbox series

[1/8] vmbus: Fix memory leak of vmstate_gpadl

Message ID 20201226103347.868-2-gaojinhao@huawei.com (mailing list archive)
State New, archived
Headers show
Series Fix memory leak of some device state in migration | expand

Commit Message

gaojinhao Dec. 26, 2020, 10:33 a.m. UTC
From: Jinhao Gao <gaojinhao@huawei.com>

When VM migrate VMState of vmbus/gpadl, the field(gfns) of vmbus/
gpadl having a flag of VMS_ALLOC needs to allocate memory. If the
dst doesn't free memory which has been allocated for SaveStateEntry
of vmbus/gpadl before dst loads device state, it may result that
the pointer of gfns 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/hyperv/vmbus.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
diff mbox series

Patch

diff --git a/hw/hyperv/vmbus.c b/hw/hyperv/vmbus.c
index 896e981f85..a91623aaac 100644
--- a/hw/hyperv/vmbus.c
+++ b/hw/hyperv/vmbus.c
@@ -519,10 +519,21 @@  void vmbus_unmap_sgl(VMBusChanReq *req, DMADirection dir, struct iovec *iov,
     }
 }
 
+static int vmbus_gpadl_pre_load(void *opaque)
+{
+    VMBusGpadl *gpadl = VMBusGpadl(opaque);
+
+    g_free(gpadl->gfns);
+    gpadl->gfns = NULL;
+    gpadl->num_gfns =0;
+    return 0;
+}
+
 static const VMStateDescription vmstate_gpadl = {
     .name = "vmbus/gpadl",
     .version_id = 0,
     .minimum_version_id = 0,
+    .pre_load = vmbus_gpadl_pre_load,
     .fields = (VMStateField[]) {
         VMSTATE_UINT32(id, VMBusGpadl),
         VMSTATE_UINT32(child_relid, VMBusGpadl),