qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Jason Wang <jasowang@redhat.com>
To: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>,
	qemu-devel@nongnu.org
Cc: den@openvz.org
Subject: Re: [PATCH 5/5] net/tap: net_init_tap_one(): fix net-client leak on failure path
Date: Tue, 12 Jan 2021 12:53:29 +0800	[thread overview]
Message-ID: <3c1f4d68-c0e9-4ecc-fede-e575e77be8e3@redhat.com> (raw)
In-Reply-To: <20201221190609.93768-6-vsementsov@virtuozzo.com>


On 2020/12/22 上午3:06, Vladimir Sementsov-Ogievskiy wrote:
> net_tap_fd_init() allocates new NetClientState through
> qemu_new_net_client(). We should free it on failure path.
>
> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
> ---
>
> Attention: it's an intuitive patch.
>
> I see, that net-client is leaked. May be it's still freed some tricky
> way? And I don't understand the whole logic of qemu_del_net_client(),
> it's just the only public interface to free net-client I found.


Your patch looks correct and it's indeed a leak.

I wonder whether it's better to do the cleanup in the free_fail label in 
net_init_tap(). The reason is that we need deal with case of multiqueue. 
Though qemu_del_net_client() can handle this but it's not clear if we do 
it in net_init_tap_one().

Thanks


>
>   net/tap.c | 9 ++++++++-
>   1 file changed, 8 insertions(+), 1 deletion(-)
>
> diff --git a/net/tap.c b/net/tap.c
> index 89ea04862b..ba4c34af3d 100644
> --- a/net/tap.c
> +++ b/net/tap.c
> @@ -711,7 +711,7 @@ static void net_init_tap_one(const NetdevTapOptions *tap, NetClientState *peer,
>   
>       ret = tap_set_sndbuf(s->fd, tap, errp);
>       if (ret < 0) {
> -        return;
> +        goto fail;
>       }
>   
>       if (tap->has_fd || tap->has_fds) {
> @@ -739,13 +739,20 @@ static void net_init_tap_one(const NetdevTapOptions *tap, NetClientState *peer,
>           if (ret < 0) {
>               if (tap->has_vhostforce && tap->vhostforce) {
>                   error_propagate(errp, err);
> +                goto fail;
>               } else {
>                   warn_report_err(err);
>               }
>           }
>       } else if (vhostfdname) {
>           error_setg(errp, "vhostfd(s)= is not valid without vhost");
> +        goto fail;
>       }
> +
> +    return;
> +
> +fail:
> +    qemu_del_net_client(&s->nc);
>   }
>   
>   static int get_fds(char *str, char *fds[], int max)



  reply	other threads:[~2021-01-12  4:59 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-21 19:06 [PATCH 0/5] net/tap: some fixes and refactorings Vladimir Sementsov-Ogievskiy
2020-12-21 19:06 ` [PATCH 1/5] net/tap: fix net_init_tap(): set ret on failure path Vladimir Sementsov-Ogievskiy
2020-12-21 19:06 ` [PATCH 2/5] net/tap: drop duplicated tap stubs Vladimir Sementsov-Ogievskiy
2020-12-21 19:06 ` [PATCH 3/5] net/tap: tap_set_sndbuf(): return status Vladimir Sementsov-Ogievskiy
2020-12-21 20:12   ` Philippe Mathieu-Daudé
2020-12-22  9:50     ` Vladimir Sementsov-Ogievskiy
2020-12-21 19:06 ` [PATCH 4/5] net/tap: refactor and improve net_init_tap_one() Vladimir Sementsov-Ogievskiy
2020-12-21 19:06 ` [PATCH 5/5] net/tap: net_init_tap_one(): fix net-client leak on failure path Vladimir Sementsov-Ogievskiy
2021-01-12  4:53   ` Jason Wang [this message]
2021-12-23 16:45     ` Vladimir Sementsov-Ogievskiy
2021-01-09  9:58 ` [PATCH 0/5] net/tap: some fixes and refactorings Vladimir Sementsov-Ogievskiy

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=3c1f4d68-c0e9-4ecc-fede-e575e77be8e3@redhat.com \
    --to=jasowang@redhat.com \
    --cc=den@openvz.org \
    --cc=qemu-devel@nongnu.org \
    --cc=vsementsov@virtuozzo.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).