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 = {