From 31cb4721e1b33f8705cef6efc5c3424d03951e39 Mon Sep 17 00:00:00 2001 From: Zhao Yakui Date: Wed, 13 Mar 2019 14:57:02 +0800 Subject: [PATCH] acrn/dm: Remove the memory leak in gvt mediator Otherwise it causes the memory leak. V1->V2: Fix the leak of pi->arg as gvt structure also needs to be released. Tracked-On: #2762 Signed-off-by: Zhao Yakui Reviewed-by: He, Min Acked-by: Yin Fengwei --- devicemodel/hw/pci/gvt.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/devicemodel/hw/pci/gvt.c b/devicemodel/hw/pci/gvt.c index f0d8eaffe..c34b5e19f 100644 --- a/devicemodel/hw/pci/gvt.c +++ b/devicemodel/hw/pci/gvt.c @@ -262,9 +262,18 @@ pci_gvt_deinit(struct vmctx *ctx, struct pci_vdev *pi, char *opts) int ret; struct pci_gvt *gvt = pi->arg; + if (gvt && gvt->host_config) { + /* Free the allocated host_config */ + free(gvt->host_config); + gvt->host_config = NULL; + } + ret = gvt_destroy_instance(gvt); if (ret) WPRINTF(("GVT: %s: failed: errno=%d\n", __func__, ret)); + + free(gvt); + pi->arg = NULL; } struct pci_vdev_ops pci_ops_gvt = {