From 49563b2a115a256dabb90b98d16b2668f860f723 Mon Sep 17 00:00:00 2001 From: Yonghua Huang Date: Tue, 23 Apr 2019 01:13:20 +0800 Subject: [PATCH] dm: fix possible null pointer dereference in pci_gvt_deinit will access null pointer if 'gvt' is null. Tracked-On: #1479 Signed-off-by: Yonghua Huang Reviewed-by: He, Min --- devicemodel/hw/pci/gvt.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/devicemodel/hw/pci/gvt.c b/devicemodel/hw/pci/gvt.c index c34b5e19f..82af03e88 100644 --- a/devicemodel/hw/pci/gvt.c +++ b/devicemodel/hw/pci/gvt.c @@ -262,18 +262,20 @@ 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; + if (gvt) { + if (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; } - - 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 = {