[PATCH 1/2] ACRN: DM: Release vsock struct in case memory leak


Long Liu
 

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


Yu Wang
 

On Tue, Jun 14, 2022 at 09:23:55AM +0800, Liu Long wrote:
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)) {
return 0 for success or fail?

+ 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


Long Liu
 

-----Original Message-----
From: acrn-dev@... <acrn-dev@...> On Behalf Of Yu Wang
Sent: Tuesday, June 14, 2022 9:04 AM
To: Liu Long <long.liu@...>
Cc: Huang, Yonghua <yonghua.huang@...>; acrn-dev@...
Subject: Re: [acrn-dev] [PATCH 1/2] ACRN: DM: Release vsock struct in case memory leak

On Tue, Jun 14, 2022 at 09:23:55AM +0800, Liu Long wrote:
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)) {
return 0 for success or fail?
[Long:] return 0 is success, if this fail force close the vhost_vsock, because this is the deinit function.

+ 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


Yu Wang
 

On Tue, Jun 14, 2022 at 01:28:33AM +0000, Long Liu wrote:


-----Original Message-----
From: acrn-dev@... <acrn-dev@...> On Behalf Of Yu Wang
Sent: Tuesday, June 14, 2022 9:04 AM
To: Liu Long <long.liu@...>
Cc: Huang, Yonghua <yonghua.huang@...>; acrn-dev@...
Subject: Re: [acrn-dev] [PATCH 1/2] ACRN: DM: Release vsock struct in case memory leak

On Tue, Jun 14, 2022 at 09:23:55AM +0800, Liu Long wrote:
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)) {
return 0 for success or fail?
[Long:] return 0 is success, if this fail force close the vhost_vsock, because this is the deinit function.
In the vhost_vsock_deinit, it already close and free, why do it again?

+ 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