From: Jinhao Gao <gaojin...@huawei.com> When VM migrate VMState of vmbus/vmbus_chan_req, the field(msg) of vmbus/vmbus_chan_req 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/vmbus_chan_req before dst loads device state, it may result that the pointer of msg 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 a91623aaac..9eda2341f3 100644 --- a/hw/hyperv/vmbus.c +++ b/hw/hyperv/vmbus.c @@ -1303,10 +1303,21 @@ typedef struct VMBusChanReqSave { ScatterGatherEntry *sgl; } VMBusChanReqSave; +static int vmbus_chan_req_pre_load(void *opaque) +{ + VMBusChanReqSave *req_save = VMBusChanReqSave(opaque); + + g_free(req_save.msg); + req_save.msg = NULL; + req_save.msglen = 0; + return 0; +} + static const VMStateDescription vmstate_vmbus_chan_req = { .name = "vmbus/vmbus_chan_req", .version_id = 0, .minimum_version_id = 0, + .pre_load = vmbus_chan_req_pre_load, .fields = (VMStateField[]) { VMSTATE_UINT16(chan_idx, VMBusChanReqSave), VMSTATE_UINT16(pkt_type, VMBusChanReqSave), -- 2.23.0