qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH v2] tap: fix memory leak on success to create a tap device
@ 2018-05-31  7:28 wangyunjian
  2018-05-31  9:46 ` Jason Wang
  0 siblings, 1 reply; 4+ messages in thread
From: wangyunjian @ 2018-05-31  7:28 UTC (permalink / raw)
  To: qemu-devel; +Cc: jasowang, qemu-stable, caihe, Yunjian Wang

From: Yunjian Wang <wangyunjian@huawei.com>

The memory leak on success to create a tap device. And the nfds and
nvhosts may not be the same and need to be processed separately.

Fixes: 07825977 ("tap: fix memory leak on failure to create a multiqueue tap device")
Fixes: 264986e2 ("tap: multiqueue support")

CC: QEMU Stable <qemu-stable@nongnu.org>
Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
---
v2:
 -add commit log and cc qemu-stable with fixes tags
---
 net/tap.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/net/tap.c b/net/tap.c
index de05f20..6d7710f 100644
--- a/net/tap.c
+++ b/net/tap.c
@@ -803,7 +803,8 @@ int net_init_tap(const Netdev *netdev, const char *name,
     } else if (tap->has_fds) {
         char **fds;
         char **vhost_fds;
-        int nfds, nvhosts;
+        int nfds = 0, nvhosts = 0;
+        int ret = 0;
 
         if (tap->has_ifname || tap->has_script || tap->has_downscript ||
             tap->has_vnet_hdr || tap->has_helper || tap->has_queues ||
@@ -823,6 +824,7 @@ int net_init_tap(const Netdev *netdev, const char *name,
             if (nfds != nvhosts) {
                 error_setg(errp, "The number of fds passed does not match "
                            "the number of vhostfds passed");
+                ret = -1;
                 goto free_fail;
             }
         }
@@ -831,6 +833,7 @@ int net_init_tap(const Netdev *netdev, const char *name,
             fd = monitor_fd_param(cur_mon, fds[i], &err);
             if (fd == -1) {
                 error_propagate(errp, err);
+                ret = -1;
                 goto free_fail;
             }
 
@@ -841,6 +844,7 @@ int net_init_tap(const Netdev *netdev, const char *name,
             } else if (vnet_hdr != tap_probe_vnet_hdr(fd)) {
                 error_setg(errp,
                            "vnet_hdr not consistent across given tap fds");
+                ret = -1;
                 goto free_fail;
             }
 
@@ -850,21 +854,21 @@ int net_init_tap(const Netdev *netdev, const char *name,
                              vnet_hdr, fd, &err);
             if (err) {
                 error_propagate(errp, err);
+                ret = -1;
                 goto free_fail;
             }
         }
-        g_free(fds);
-        g_free(vhost_fds);
-        return 0;
 
 free_fail:
+        for (i = 0; i < nvhosts; i++) {
+            g_free(vhost_fds[i]);
+        }
         for (i = 0; i < nfds; i++) {
             g_free(fds[i]);
-            g_free(vhost_fds[i]);
         }
         g_free(fds);
         g_free(vhost_fds);
-        return -1;
+        return ret;
     } else if (tap->has_helper) {
         if (tap->has_ifname || tap->has_script || tap->has_downscript ||
             tap->has_vnet_hdr || tap->has_queues || tap->has_vhostfds) {
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] [PATCH v2] tap: fix memory leak on success to create a tap device
  2018-05-31  7:28 [Qemu-devel] [PATCH v2] tap: fix memory leak on success to create a tap device wangyunjian
@ 2018-05-31  9:46 ` Jason Wang
  2018-07-18 16:32   ` [Qemu-devel] [Qemu-stable] " Michael Roth
  0 siblings, 1 reply; 4+ messages in thread
From: Jason Wang @ 2018-05-31  9:46 UTC (permalink / raw)
  To: wangyunjian, qemu-devel; +Cc: qemu-stable, caihe



On 2018年05月31日 15:28, wangyunjian wrote:
> From: Yunjian Wang <wangyunjian@huawei.com>
>
> The memory leak on success to create a tap device. And the nfds and
> nvhosts may not be the same and need to be processed separately.
>
> Fixes: 07825977 ("tap: fix memory leak on failure to create a multiqueue tap device")
> Fixes: 264986e2 ("tap: multiqueue support")
>
> CC: QEMU Stable <qemu-stable@nongnu.org>
> Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
> ---
> v2:
>   -add commit log and cc qemu-stable with fixes tags
> ---

Applied.

Thanks

>   net/tap.c | 16 ++++++++++------
>   1 file changed, 10 insertions(+), 6 deletions(-)
>
> diff --git a/net/tap.c b/net/tap.c
> index de05f20..6d7710f 100644
> --- a/net/tap.c
> +++ b/net/tap.c
> @@ -803,7 +803,8 @@ int net_init_tap(const Netdev *netdev, const char *name,
>       } else if (tap->has_fds) {
>           char **fds;
>           char **vhost_fds;
> -        int nfds, nvhosts;
> +        int nfds = 0, nvhosts = 0;
> +        int ret = 0;
>   
>           if (tap->has_ifname || tap->has_script || tap->has_downscript ||
>               tap->has_vnet_hdr || tap->has_helper || tap->has_queues ||
> @@ -823,6 +824,7 @@ int net_init_tap(const Netdev *netdev, const char *name,
>               if (nfds != nvhosts) {
>                   error_setg(errp, "The number of fds passed does not match "
>                              "the number of vhostfds passed");
> +                ret = -1;
>                   goto free_fail;
>               }
>           }
> @@ -831,6 +833,7 @@ int net_init_tap(const Netdev *netdev, const char *name,
>               fd = monitor_fd_param(cur_mon, fds[i], &err);
>               if (fd == -1) {
>                   error_propagate(errp, err);
> +                ret = -1;
>                   goto free_fail;
>               }
>   
> @@ -841,6 +844,7 @@ int net_init_tap(const Netdev *netdev, const char *name,
>               } else if (vnet_hdr != tap_probe_vnet_hdr(fd)) {
>                   error_setg(errp,
>                              "vnet_hdr not consistent across given tap fds");
> +                ret = -1;
>                   goto free_fail;
>               }
>   
> @@ -850,21 +854,21 @@ int net_init_tap(const Netdev *netdev, const char *name,
>                                vnet_hdr, fd, &err);
>               if (err) {
>                   error_propagate(errp, err);
> +                ret = -1;
>                   goto free_fail;
>               }
>           }
> -        g_free(fds);
> -        g_free(vhost_fds);
> -        return 0;
>   
>   free_fail:
> +        for (i = 0; i < nvhosts; i++) {
> +            g_free(vhost_fds[i]);
> +        }
>           for (i = 0; i < nfds; i++) {
>               g_free(fds[i]);
> -            g_free(vhost_fds[i]);
>           }
>           g_free(fds);
>           g_free(vhost_fds);
> -        return -1;
> +        return ret;
>       } else if (tap->has_helper) {
>           if (tap->has_ifname || tap->has_script || tap->has_downscript ||
>               tap->has_vnet_hdr || tap->has_queues || tap->has_vhostfds) {

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] [Qemu-stable] [PATCH v2] tap: fix memory leak on success to create a tap device
  2018-05-31  9:46 ` Jason Wang
@ 2018-07-18 16:32   ` Michael Roth
  2018-07-19  8:53     ` Jason Wang
  0 siblings, 1 reply; 4+ messages in thread
From: Michael Roth @ 2018-07-18 16:32 UTC (permalink / raw)
  To: Jason Wang, qemu-devel, wangyunjian; +Cc: caihe, qemu-stable

Quoting Jason Wang (2018-05-31 04:46:05)
> 
> 
> On 2018年05月31日 15:28, wangyunjian wrote:
> > From: Yunjian Wang <wangyunjian@huawei.com>
> >
> > The memory leak on success to create a tap device. And the nfds and
> > nvhosts may not be the same and need to be processed separately.
> >
> > Fixes: 07825977 ("tap: fix memory leak on failure to create a multiqueue tap device")
> > Fixes: 264986e2 ("tap: multiqueue support")
> >
> > CC: QEMU Stable <qemu-stable@nongnu.org>
> > Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
> > ---
> > v2:
> >   -add commit log and cc qemu-stable with fixes tags
> > ---
> 
> Applied.

It looks like this hasn't made its way to master yet. Is a pull request
still planned?

> 
> Thanks
> 
> >   net/tap.c | 16 ++++++++++------
> >   1 file changed, 10 insertions(+), 6 deletions(-)
> >
> > diff --git a/net/tap.c b/net/tap.c
> > index de05f20..6d7710f 100644
> > --- a/net/tap.c
> > +++ b/net/tap.c
> > @@ -803,7 +803,8 @@ int net_init_tap(const Netdev *netdev, const char *name,
> >       } else if (tap->has_fds) {
> >           char **fds;
> >           char **vhost_fds;
> > -        int nfds, nvhosts;
> > +        int nfds = 0, nvhosts = 0;
> > +        int ret = 0;
> >   
> >           if (tap->has_ifname || tap->has_script || tap->has_downscript ||
> >               tap->has_vnet_hdr || tap->has_helper || tap->has_queues ||
> > @@ -823,6 +824,7 @@ int net_init_tap(const Netdev *netdev, const char *name,
> >               if (nfds != nvhosts) {
> >                   error_setg(errp, "The number of fds passed does not match "
> >                              "the number of vhostfds passed");
> > +                ret = -1;
> >                   goto free_fail;
> >               }
> >           }
> > @@ -831,6 +833,7 @@ int net_init_tap(const Netdev *netdev, const char *name,
> >               fd = monitor_fd_param(cur_mon, fds[i], &err);
> >               if (fd == -1) {
> >                   error_propagate(errp, err);
> > +                ret = -1;
> >                   goto free_fail;
> >               }
> >   
> > @@ -841,6 +844,7 @@ int net_init_tap(const Netdev *netdev, const char *name,
> >               } else if (vnet_hdr != tap_probe_vnet_hdr(fd)) {
> >                   error_setg(errp,
> >                              "vnet_hdr not consistent across given tap fds");
> > +                ret = -1;
> >                   goto free_fail;
> >               }
> >   
> > @@ -850,21 +854,21 @@ int net_init_tap(const Netdev *netdev, const char *name,
> >                                vnet_hdr, fd, &err);
> >               if (err) {
> >                   error_propagate(errp, err);
> > +                ret = -1;
> >                   goto free_fail;
> >               }
> >           }
> > -        g_free(fds);
> > -        g_free(vhost_fds);
> > -        return 0;
> >   
> >   free_fail:
> > +        for (i = 0; i < nvhosts; i++) {
> > +            g_free(vhost_fds[i]);
> > +        }
> >           for (i = 0; i < nfds; i++) {
> >               g_free(fds[i]);
> > -            g_free(vhost_fds[i]);
> >           }
> >           g_free(fds);
> >           g_free(vhost_fds);
> > -        return -1;
> > +        return ret;
> >       } else if (tap->has_helper) {
> >           if (tap->has_ifname || tap->has_script || tap->has_downscript ||
> >               tap->has_vnet_hdr || tap->has_queues || tap->has_vhostfds) {
> 
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] [Qemu-stable] [PATCH v2] tap: fix memory leak on success to create a tap device
  2018-07-18 16:32   ` [Qemu-devel] [Qemu-stable] " Michael Roth
@ 2018-07-19  8:53     ` Jason Wang
  0 siblings, 0 replies; 4+ messages in thread
From: Jason Wang @ 2018-07-19  8:53 UTC (permalink / raw)
  To: Michael Roth, qemu-devel, wangyunjian; +Cc: caihe, qemu-stable



On 2018年07月19日 00:32, Michael Roth wrote:
> Quoting Jason Wang (2018-05-31 04:46:05)
>> On 2018年05月31日 15:28, wangyunjian wrote:
>>> From: Yunjian Wang<wangyunjian@huawei.com>
>>>
>>> The memory leak on success to create a tap device. And the nfds and
>>> nvhosts may not be the same and need to be processed separately.
>>>
>>> Fixes: 07825977 ("tap: fix memory leak on failure to create a multiqueue tap device")
>>> Fixes: 264986e2 ("tap: multiqueue support")
>>>
>>> CC: QEMU Stable<qemu-stable@nongnu.org>
>>> Signed-off-by: Yunjian Wang<wangyunjian@huawei.com>
>>> ---
>>> v2:
>>>    -add commit log and cc qemu-stable with fixes tags
>>> ---
>> Applied.
> It looks like this hasn't made its way to master yet. Is a pull request
> still planned?
>

Fall through cracks unfortuately. It will be included in the next pull 
request.

Thanks

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2018-07-19  8:54 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-05-31  7:28 [Qemu-devel] [PATCH v2] tap: fix memory leak on success to create a tap device wangyunjian
2018-05-31  9:46 ` Jason Wang
2018-07-18 16:32   ` [Qemu-devel] [Qemu-stable] " Michael Roth
2018-07-19  8:53     ` Jason Wang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).