qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Jason Wang <jasowang@redhat.com>
To: wangyunjian <wangyunjian@huawei.com>, qemu-devel@nongnu.org
Cc: caihe@huawei.com
Subject: Re: [Qemu-devel] [PATCH] tap: fix memory leak on success to create a tap device
Date: Thu, 31 May 2018 09:56:11 +0800	[thread overview]
Message-ID: <4f60effa-ada2-9940-f844-ec9be7a18596@redhat.com> (raw)
In-Reply-To: <1527688331-9044-1-git-send-email-wangyunjian@huawei.com>



On 2018年05月30日 21:52, wangyunjian wrote:
> From: Yunjian Wang <wangyunjian@huawei.com>
>
> Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
> ---

Looks good, but please add some commit log and cc qemu-stable with Fixes 
tags.

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) {

      reply	other threads:[~2018-05-31  1:56 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-30 13:52 [Qemu-devel] [PATCH] tap: fix memory leak on success to create a tap device wangyunjian
2018-05-31  1:56 ` Jason Wang [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4f60effa-ada2-9940-f844-ec9be7a18596@redhat.com \
    --to=jasowang@redhat.com \
    --cc=caihe@huawei.com \
    --cc=qemu-devel@nongnu.org \
    --cc=wangyunjian@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).