DM: vsock: fix the memory leakage bug

Fix the memory leakage issue caused by incomplete deinit flow.

Tracked-On: #7759
Signed-off-by: Liu Long <long.liu@linux.intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
This commit is contained in:
Liu Long 2022-06-14 13:18:21 +08:00 committed by acrnsi-robot
parent b2d9112ed5
commit 038335367d
1 changed files with 6 additions and 11 deletions

View File

@ -208,25 +208,21 @@ fail:
return NULL; return NULL;
} }
static int static void
vhost_vsock_deinit(struct vhost_vsock *vhost_vsock) vhost_vsock_deinit(struct vhost_vsock *vhost_vsock)
{ {
int rc; int rc;
rc = vhost_vsock_stop(vhost_vsock); rc = vhost_vsock_stop(vhost_vsock);
if (rc < 0) { if (rc < 0)
pr_err("vhost_dev_stop is failed!\n"); pr_err("vhost_dev_stop is failed!\n");
return -1;
}
rc = vhost_dev_deinit(&vhost_vsock->vdev); rc = vhost_dev_deinit(&vhost_vsock->vdev);
if (rc < 0) { if (rc < 0)
pr_err("vhost_dev_deinit is failed!\n"); pr_err("vhost_dev_deinit is failed!\n");
return -1;
}
close(vhost_vsock->vhost_fd); close(vhost_vsock->vhost_fd);
free(vhost_vsock); free(vhost_vsock);
return 0;
} }
static void static void
@ -323,10 +319,9 @@ virtio_vhost_vsock_deinit(struct vmctx *ctx, struct pci_vdev *dev, char *opts)
if (dev->arg) { if (dev->arg) {
vsock = (struct virtio_vsock *) dev->arg; vsock = (struct virtio_vsock *) dev->arg;
if (vsock->vhost_vsock) { if (vsock->vhost_vsock)
vhost_vsock_deinit(vsock->vhost_vsock); vhost_vsock_deinit(vsock->vhost_vsock);
} pr_dbg("%s: done\n", __func__);
pr_dbg("%s: done\n", __func__);
} else } else
pr_err("%s: NULL!\n", __func__); pr_err("%s: NULL!\n", __func__);
} }