From: Jinhao Gao <gaojin...@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 <gaojin...@huawei.com> --- hw/hyperv/vmbus.c | 11 +++++++++++ 1 file changed, 11 insertions(+) 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), -- 2.23.0