qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Gonglei <arei.gonglei@huawei.com>
To: Michael Tokarev <mjt@tls.msk.ru>
Cc: "qemu-trivial@nongnu.org" <qemu-trivial@nongnu.org>,
	"qemu-devel@nongnu.org" <qemu-devel@nongnu.org>,
	"stefanha@redhat.com" <stefanha@redhat.com>,
	"Huangpeng (Peter)" <peter.huangpeng@huawei.com>
Subject: Re: [Qemu-devel] [Qemu-trivial] [PATCH 2/2] tap: fix possible fd leak
Date: Sun, 2 Nov 2014 13:21:35 +0800	[thread overview]
Message-ID: <5455BF5F.3010400@huawei.com> (raw)
In-Reply-To: <5455BCE6.5080804@msgid.tls.msk.ru>

On 2014/11/2 13:11, Michael Tokarev wrote:

> 31.10.2014 09:11, arei.gonglei@huawei.com wrote:
>> From: Gonglei <arei.gonglei@huawei.com>
>>
>> In hotplugging scenario, taking those true branch, the file
>> handler do not be closed. Adding cleanup logic for them.
>>
>> Signed-off-by: Gonglei <arei.gonglei@huawei.com>
>> ---
>>  net/tap.c | 12 +++++++++---
>>  1 file changed, 9 insertions(+), 3 deletions(-)
>>
>> diff --git a/net/tap.c b/net/tap.c
>> index 7bcd4c7..3cfbee8 100644
>> --- a/net/tap.c
>> +++ b/net/tap.c
>> @@ -796,7 +796,7 @@ int net_init_tap(const NetClientOptions *opts, const char *name,
>>          if (net_init_tap_one(tap, peer, "bridge", name, ifname,
>>                               script, downscript, vhostfdname,
>>                               vnet_hdr, fd)) {
>> -            return -1;
>> +            goto fail;
>>          }
>>      } else {
>>          if (tap->has_vhostfds) {
>> @@ -823,7 +823,7 @@ int net_init_tap(const NetClientOptions *opts, const char *name,
>>              if (queues > 1 && i == 0 && !tap->has_ifname) {
>>                  if (tap_fd_get_ifname(fd, ifname)) {
>>                      error_report("Fail to get ifname");
>> -                    return -1;
>> +                    goto fail;
>>                  }
>>              }
>>  
>> @@ -831,12 +831,18 @@ int net_init_tap(const NetClientOptions *opts, const char *name,
>>                                   i >= 1 ? "no" : script,
>>                                   i >= 1 ? "no" : downscript,
>>                                   vhostfdname, vnet_hdr, fd)) {
>> -                return -1;
>> +                goto fail;
>>              }
>>          }
>>      }
>>  
>>      return 0;
>> +
>> +fail:
>> +    if (fd != -1) {
>> +        close(fd);
>> +    }
>> +    return -1;
>>  }
> 
> I think, given the somewhat "hairy" nature of net_init_tap() function, which
> has many error returns which should not close fd and just 3 which should, it
> is better to add explicit close(fd) in these 3 places.
> 

Agree. v2 will do. Thanks!

> Besides, why do you check for fd != -1 in the fail path?  You added the goto
> into the 3 places, all of them has fd != -1, and there's no other ways to
> reach this place.  

Yes.

> Are you not certain that fd will be valid here?  If yes,
> I think this is yet another argument for adding close()s into the 3 places.
> 


Best regards,
-Gonglei

  reply	other threads:[~2014-11-02  5:22 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-31  6:10 [Qemu-devel] [PATCH 0/2] tap: add cleanup logic avoiding leaking fd arei.gonglei
2014-10-31  6:11 ` [Qemu-devel] [PATCH 1/2] tap: remove close(fd) arei.gonglei
2014-11-02  5:06   ` [Qemu-devel] [Qemu-trivial] " Michael Tokarev
2014-11-02  5:09     ` Gonglei
2014-10-31  6:11 ` [Qemu-devel] [PATCH 2/2] tap: fix possible fd leak arei.gonglei
2014-11-02  5:11   ` [Qemu-devel] [Qemu-trivial] " Michael Tokarev
2014-11-02  5:21     ` Gonglei [this message]
2014-11-02  5:24       ` Michael Tokarev

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=5455BF5F.3010400@huawei.com \
    --to=arei.gonglei@huawei.com \
    --cc=mjt@tls.msk.ru \
    --cc=peter.huangpeng@huawei.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-trivial@nongnu.org \
    --cc=stefanha@redhat.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).