[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 6/8] vmbus: Fix memory leak of vmstate_vmbus_chan_req
From: |
g00517791 |
Subject: |
[PATCH 6/8] vmbus: Fix memory leak of vmstate_vmbus_chan_req |
Date: |
Sat, 26 Dec 2020 18:33:45 +0800 |
From: Jinhao Gao <gaojinhao@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 <gaojinhao@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
[PATCH 2/8] virtio-net: Fix memory leak of vmstate_virtio_net_rss, 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 5/8] savevm: Fix memory leak of vmstate_configuration, g00517791, 2020/12/26