qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Gonglei <arei.gonglei@huawei.com>
To: Markus Armbruster <armbru@redhat.com>
Cc: "qemu-trivial@nongnu.org" <qemu-trivial@nongnu.org>,
	"Huangpeng (Peter)" <peter.huangpeng@huawei.com>,
	"qemu-devel@nongnu.org" <qemu-devel@nongnu.org>,
	"aneesh.kumar@linux.vnet.ibm.com"
	<aneesh.kumar@linux.vnet.ibm.com>
Subject: Re: [Qemu-devel] [PATCH 2/2] virtfs-proxy-helper: Fix handle leak to make Coverity happy
Date: Fri, 28 Nov 2014 09:51:44 +0800	[thread overview]
Message-ID: <5477D530.7030101@huawei.com> (raw)
In-Reply-To: <87h9xkkdxx.fsf@blackfin.pond.sub.org>

On 2014/11/27 20:47, Markus Armbruster wrote:

> <arei.gonglei@huawei.com> writes:
> 
>> From: Gonglei <arei.gonglei@huawei.com>
>>
>> Coverity report:
>> (94) Event open_fn:  Returning handle opened by function "proxy_socket(char const *, uid_t, gid_t)". [details]
>> (95) Event var_assign:  Assigning: "sock" = handle returned from "proxy_socket(sock_name, own_u, own_g)".
>> (103) Event leaked_handle:  Handle variable "sock" going out of scope leaks the handle.
>>
>> Signed-off-by: Gonglei <arei.gonglei@huawei.com>
>> ---
>>  fsdev/virtfs-proxy-helper.c | 3 +++
>>  1 file changed, 3 insertions(+)
>>
>> diff --git a/fsdev/virtfs-proxy-helper.c b/fsdev/virtfs-proxy-helper.c
>> index c1da2d7..2d72def 100644
>> --- a/fsdev/virtfs-proxy-helper.c
>> +++ b/fsdev/virtfs-proxy-helper.c
>> @@ -1150,6 +1150,9 @@ int main(int argc, char **argv)
>>  
>>      process_requests(sock);
>>  error:
>> +    if (sock_name && sock >= 0) {
>> +        close(sock);
>> +    }
>>      do_log(LOG_INFO, "Done\n");
>>      closelog();
>>      return 0;
> 
> Why if sock_name?  What about sock gotten from -f?
>

Thanks for your review, Makus :)

 

Because only sock_name is non-NULL, the sock returned from
"proxy_socket(sock_name, own_u, own_g)", then will leak fd.
If sock gotten from -f, maybe the caller will free it IMO.

> If sock >= 0 is pointless, too, but needed to hush up Coverity.

You mean do not check sock_name is NULL or not?

Regards,
-Gonglei

  reply	other threads:[~2014-11-28  1:52 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-13 12:17 [Qemu-devel] [PATCH 0/2] virtfs-proxy-helper: Fix Coverity warning arei.gonglei
2014-11-13 12:17 ` [Qemu-devel] [PATCH 1/2] virtfs-proxy-helper: Fix possible socket leak arei.gonglei
2014-11-27 12:49   ` Markus Armbruster
2015-01-21  8:00     ` Gonglei
2015-01-21  8:06       ` [Qemu-devel] [Qemu-trivial] " Michael Tokarev
2014-11-13 12:17 ` [Qemu-devel] [PATCH 2/2] virtfs-proxy-helper: Fix handle leak to make Coverity happy arei.gonglei
2014-11-27 12:47   ` Markus Armbruster
2014-11-28  1:51     ` Gonglei [this message]
2014-11-28  7:29       ` Markus Armbruster
2014-11-28  7:41         ` Gonglei
2014-11-27 10:29 ` [Qemu-devel] [PATCH 0/2] virtfs-proxy-helper: Fix Coverity warning Gonglei
2014-11-28  8:31   ` Paolo Bonzini
2014-11-28  8:34     ` Gonglei

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=5477D530.7030101@huawei.com \
    --to=arei.gonglei@huawei.com \
    --cc=aneesh.kumar@linux.vnet.ibm.com \
    --cc=armbru@redhat.com \
    --cc=peter.huangpeng@huawei.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-trivial@nongnu.org \
    /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).