public inbox for linux-erofs@ozlabs.org
 help / color / mirror / Atom feed
From: Deepak Pathik <deepakpathik2005@gmail.com>
To: linux-erofs@lists.ozlabs.org
Cc: hsiangkao@linux.alibaba.com, xiang@kernel.org,
	Deepak Pathik <deepakpathik2005@gmail.com>
Subject: [PATCH v2] erofs-utils: lib: fix fd leak in erofs_metamgr_init()
Date: Wed, 2 Apr 2026 16:50:21 +0530	[thread overview]
Message-ID: <20260402111800.v2-1-deepakpathik2005@gmail.com> (raw)
In-Reply-To: <20260401194000.1-deepakpathik2005@gmail.com>

In erofs_metamgr_init(), erofs_tmpfile() returns a file
descriptor stored in m2gr->vf.fd. If the subsequent
erofs_buffer_init() call fails, the function returns -ENOMEM
without closing this file descriptor.

The caller erofs_metadata_init() handles this failure at
err_free, which only frees the m2gr struct. The fd is
therefore leaked with no remaining reference to close it.

The success path correctly cleans up via erofs_metamgr_exit(),
which calls erofs_io_close(&m2gr->vf). Mirror that behaviour
on the error path by closing the fd before returning.

Signed-off-by: Deepak Pathik <deepakpathik2005@gmail.com>
---
v2: use erofs_io_close() instead of raw close(); rebased on latest upstream/dev

 lib/metabox.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/lib/metabox.c b/lib/metabox.c
index d5ce9e3..86a7083 100644
--- a/lib/metabox.c
+++ b/lib/metabox.c
@@ -32,8 +32,10 @@ static int erofs_metamgr_init(struct erofs_sb_info *sbi,
 
 m2gr->vf = (struct erofs_vfile){ .fd = ret };
 	m2gr->bmgr = erofs_buffer_init(sbi, 0, &m2gr->vf);
- if (!m2gr->bmgr)
+if (!m2gr->bmgr) {
+erofs_io_close(&m2gr->vf);
 		return -ENOMEM;
+}
 	return 0;
 }
 
-- 
2.53.0



  parent reply	other threads:[~2026-04-02 11:21 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-01 19:40 [PATCH] erofs-utils: lib: fix fd leak in erofs_metamgr_init() Deepak Pathik
2026-04-02  4:28 ` Utkal Singh
2026-04-02  6:23   ` Deepak Pathik
2026-04-02 11:20 ` Deepak Pathik [this message]
2026-04-02 11:26 ` [PATCH v3] " Deepak Pathik

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=20260402111800.v2-1-deepakpathik2005@gmail.com \
    --to=deepakpathik2005@gmail.com \
    --cc=hsiangkao@linux.alibaba.com \
    --cc=linux-erofs@lists.ozlabs.org \
    --cc=xiang@kernel.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