qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Jie Wang <wangjie88@huawei.com>
To: <qemu-devel@nongnu.org>
Cc: wangxinxin.wang@huawei.com, wangjie88@huawei.com
Subject: [PATCH v2] util: fix fd leak in qemu_write_pidfile()
Date: Mon, 10 May 2021 22:11:48 +0800	[thread overview]
Message-ID: <20210510141148.3138904-1-wangjie88@huawei.com> (raw)

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");
-- 
2.23.0



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

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-10 14:11 Jie Wang [this message]
2021-05-10 15:07 ` [PATCH v2] util: fix fd leak in qemu_write_pidfile() Peter Maydell
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=20210510141148.3138904-1-wangjie88@huawei.com \
    --to=wangjie88@huawei.com \
    --cc=qemu-devel@nongnu.org \
    --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 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).