From: Greg Kurz <groug@kaod.org>
To: Christian Schoenebeck <qemu_oss@crudebyte.com>
Cc: Alex Chen <alex.chen@huawei.com>,
qemu-trivial@nongnu.org, qemu-devel@nongnu.org,
zhang.zhanghailiang@huawei.com
Subject: Re: [PATCH] virtfs-proxy-helper: Fix a resource leak in main()
Date: Thu, 26 Nov 2020 19:27:19 +0100 [thread overview]
Message-ID: <20201126192719.7ea20846@bahia.lan> (raw)
In-Reply-To: <2017010.0bgJjaKMus@silver>
On Thu, 26 Nov 2020 18:52:39 +0100
Christian Schoenebeck <qemu_oss@crudebyte.com> wrote:
> On Donnerstag, 26. November 2020 14:15:51 CET Alex Chen wrote:
> > Hi Greg,
> >
> > Thanks for your review.
> >
> > On 2020/11/26 20:07, Greg Kurz wrote:
> > > On Thu, 26 Nov 2020 10:16:24 +0000
> > >
> > > Alex Chen <alex.chen@huawei.com> wrote:
> > >> Only one of the options -s and -f can be used. When -f is used,
> > >> the fd is created externally and does not need to be closed.
>
> So somebody is really using the 9p proxy driver for something; interesting.
>
> > >
> > > The process running virtfs-proxy-helper has its own copy of
> > > the fd inherited from its parent. And this fd will be closed
> > > eventually when the process terminates.
> > >
> > >> When -s is used, a new socket fd is created, and this socket fd
> > >> needs to be closed at the end of main().
> > >
> > > Same here, the new socket fd is closed when the process
> > > terminates.
>
> Does it? I haven't reviewed much of the 9p proxy code yet, however if chroot()
> fails for instance, the fd would leak right now, wouldn't it?
>
This is done just at the end of main()... the leak won't last long.
> Or was your argument that it's the OS's job to free any file descriptor
> automatically on process terminations in general?
>
That's exactly my point.
The only justification that'd deserve to be in the changelog of
such a patch is something like "because this is good practice
to rollback in case code moves to another function than main()".
> > IMO, it's best to explicitly release resources before the process
> > terminates, just as the variable 'rpath' is explicitly freed in main(),
> > so socket fd also needs to be explicitly closed here.
> >
> > Looking forward to your reply.
> >
> > > The only justification to merge such a change would be if
> > > the code was sitting in some other function, in which
> > > case we should indeed do proper rollback. But it is main()
> > > here, so this patch isn't needed.
> > >
> > >> Reported-by: Euler Robot <euler.robot@huawei.com>
> > >
> > > Can you provide a copy of the report in case I'm
> > > missing something ?
> >
> > Our codecheck tool reports a resource leak here, which is relatively simple,
> > like the one below, I did not attach it.
> >
> > ---------------------
> > "Resource leak: sock"
> > ---------------------
>
> Yeah, not very helpful that output.
>
Indeed :D
> >
> > Thanks,
> > Alex
>
> Best regards,
> Christian Schoenebeck
>
>
next prev parent reply other threads:[~2020-11-26 18:29 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-26 10:16 [PATCH] virtfs-proxy-helper: Fix a resource leak in main() Alex Chen
2020-11-26 10:50 ` Li Qiang
2020-11-26 11:40 ` Alex Chen
2020-11-26 15:04 ` Li Qiang
2020-11-26 12:07 ` Greg Kurz
2020-11-26 13:15 ` Alex Chen
2020-11-26 17:52 ` Christian Schoenebeck
2020-11-26 18:27 ` Greg Kurz [this message]
2020-11-26 18:44 ` Christian Schoenebeck
2020-11-27 9:10 ` Greg Kurz
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=20201126192719.7ea20846@bahia.lan \
--to=groug@kaod.org \
--cc=alex.chen@huawei.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-trivial@nongnu.org \
--cc=qemu_oss@crudebyte.com \
--cc=zhang.zhanghailiang@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).