When deinit the vhost vsock release the vhost vsock struct to prevent
memory leak.
Signed-off-by: Liu Long <long.liu@...>
---
devicemodel/hw/pci/virtio/vhost_vsock.c | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)
diff --git a/devicemodel/hw/pci/virtio/vhost_vsock.c b/devicemodel/hw/pci/virtio/vhost_vsock.c
index e2aa06acd..544c392df 100644
--- a/devicemodel/hw/pci/virtio/vhost_vsock.c
+++ b/devicemodel/hw/pci/virtio/vhost_vsock.c
@@ -211,22 +211,21 @@ fail:
static int
vhost_vsock_deinit(struct vhost_vsock *vhost_vsock)
{
- int rc;
+ int rc = 0;
rc = vhost_vsock_stop(vhost_vsock);
if (rc < 0) {
pr_err("vhost_dev_stop is failed.\n");
- return -1;
}
rc = vhost_dev_deinit(&vhost_vsock->vdev);
if (rc < 0) {
pr_err("vhost_dev_deinit is failed.\n");
- return -1;
}
+
close(vhost_vsock->vhost_fd);
free(vhost_vsock);
- return 0;
+ return rc;
}
static void
@@ -324,9 +323,12 @@ virtio_vhost_vsock_deinit(struct vmctx *ctx, struct pci_vdev *dev, char *opts)
vsock = (struct virtio_vsock *) dev->arg;
if (vsock->vhost_vsock) {
- vhost_vsock_deinit(vsock->vhost_vsock);
+ if (vhost_vsock_deinit(vsock->vhost_vsock)) {
+ close(vsock->vhost_vsock->vhost_fd);
+ free(vsock->vhost_vsock);
+ }
}
- pr_dbg("%s: done\n", __func__);
+ pr_dbg("%s: done\n", __func__);
} else
pr_err("%s: NULL.\n", __func__);
}
--
2.25.1