All of lore.kernel.org
 help / color / mirror / Atom feed
From: Peter Maydell <peter.maydell@linaro.org>
To: Jie Wang <wangjie88@huawei.com>
Cc: wangxinxin.wang@huawei.com, QEMU Developers <qemu-devel@nongnu.org>
Subject: Re: [PATCH v2] util: fix fd leak in qemu_write_pidfile()
Date: Mon, 10 May 2021 16:07:51 +0100	[thread overview]
Message-ID: <CAFEAcA9g8XWrvZGSOFdHQEkabGSDbcxQCnD8adfxR=0KLK=GeQ@mail.gmail.com> (raw)
In-Reply-To: <20210510141148.3138904-1-wangjie88@huawei.com>

On Mon, 10 May 2021 at 15:15, Jie Wang <wangjie88@huawei.com> wrote:
>
> if execute qemu_open success, have no branch to free the fd,
> so unlink it inadvance, let it free by process exit.
>
> Signed-off-by: Jie Wang <wangjie88@huawei.com>
> ---
>  util/oslib-posix.c | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/util/oslib-posix.c b/util/oslib-posix.c
> index 36820fec16..fa881f2ee8 100644
> --- a/util/oslib-posix.c
> +++ b/util/oslib-posix.c
> @@ -131,6 +131,7 @@ bool qemu_write_pidfile(const char *path, Error **errp)
>              error_setg_errno(errp, errno, "Cannot open pid file");
>              return false;
>          }
> +        unlink(path);
>
>          if (fstat(fd, &b) < 0) {
>              error_setg_errno(errp, errno, "Cannot stat file");

This code change doesn't match the commit message -- the commit
message says it's trying to free a filedescriptor, but the code
change is unlinking a file.

Unlinking the file is definitely wrong, because the purpose of the
pidfile is to comminucate the QEMU PID to other processes -- if we
delete the file then those other processes can't find it. (The file
gets deleted when QEMU exits -- see qemu_unlink_pidfile() and the code
that calls it.)

thanks
-- PMM


  reply	other threads:[~2021-05-10 15:10 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-10 14:11 [PATCH v2] util: fix fd leak in qemu_write_pidfile() Jie Wang
2021-05-10 15:07 ` Peter Maydell [this message]
2021-05-10 15:22   ` Daniel P. Berrangé

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='CAFEAcA9g8XWrvZGSOFdHQEkabGSDbcxQCnD8adfxR=0KLK=GeQ@mail.gmail.com' \
    --to=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=wangjie88@huawei.com \
    --cc=wangxinxin.wang@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.