[PATCH 5/7] vhost-vdpa: fix improper cleanup in net_init_vhost_vdpa

Si-Wei Liu posted 7 patches 3 years, 7 months ago
Maintainers: "Michael S. Tsirkin" <mst@redhat.com>, Jason Wang <jasowang@redhat.com>
There is a newer version of this series
[PATCH 5/7] vhost-vdpa: fix improper cleanup in net_init_vhost_vdpa
Posted by Si-Wei Liu 3 years, 7 months ago
... such that no memory leaks on dangling net clients in case of
error.

Signed-off-by: Si-Wei Liu <si-wei.liu@oracle.com>
---
 net/vhost-vdpa.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c
index 1e9fe47..df1e69e 100644
--- a/net/vhost-vdpa.c
+++ b/net/vhost-vdpa.c
@@ -306,7 +306,9 @@ int net_init_vhost_vdpa(const Netdev *netdev, const char *name,
 
 err:
     if (i) {
-        qemu_del_net_client(ncs[0]);
+        for (i--; i >= 0; i--) {
+            qemu_del_net_client(ncs[i]);
+        }
     }
     qemu_close(vdpa_device_fd);
 
-- 
1.8.3.1
Re: [PATCH 5/7] vhost-vdpa: fix improper cleanup in net_init_vhost_vdpa
Posted by Jason Wang 3 years, 7 months ago
On Wed, Mar 30, 2022 at 2:33 PM Si-Wei Liu <si-wei.liu@oracle.com> wrote:
>
> ... such that no memory leaks on dangling net clients in case of
> error.
>
> Signed-off-by: Si-Wei Liu <si-wei.liu@oracle.com>

Acked-by: Jason Wang <jasowang@redhat.com>

> ---
>  net/vhost-vdpa.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c
> index 1e9fe47..df1e69e 100644
> --- a/net/vhost-vdpa.c
> +++ b/net/vhost-vdpa.c
> @@ -306,7 +306,9 @@ int net_init_vhost_vdpa(const Netdev *netdev, const char *name,
>
>  err:
>      if (i) {
> -        qemu_del_net_client(ncs[0]);
> +        for (i--; i >= 0; i--) {
> +            qemu_del_net_client(ncs[i]);
> +        }
>      }
>      qemu_close(vdpa_device_fd);
>
> --
> 1.8.3.1
>