public inbox for linux-btrfs@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] btrfs: fix the resource leak issue in btrfs_iget()
@ 2025-04-21 10:32 Penglei Jiang
  2025-04-21 10:42 ` Qu Wenruo
  0 siblings, 1 reply; 5+ messages in thread
From: Penglei Jiang @ 2025-04-21 10:32 UTC (permalink / raw)
  To: clm, josef, dsterba; +Cc: linux-btrfs, linux-kernel, Penglei Jiang

When btrfs_iget() returns an error, it does not use iget_failed() to mark
and release the inode. Now, we add the missing iget_failed() call.

Reported-by: Penglei Jiang <superman.xpt@gmail.com>
Closes: https://lore.kernel.org/all/20250421102425.44431-1-superman.xpt@gmail.com
Signed-off-by: Penglei Jiang <superman.xpt@gmail.com>
---
 fs/btrfs/inode.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index cc67d1a2d611..61d7f3f94090 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -5681,16 +5681,22 @@ struct btrfs_inode *btrfs_iget(u64 ino, struct btrfs_root *root)
 		return inode;
 
 	path = btrfs_alloc_path();
-	if (!path)
-		return ERR_PTR(-ENOMEM);
+	if (!path) {
+		ret = -ENOMEM;
+		goto bad_inode;
+	}
 
 	ret = btrfs_read_locked_inode(inode, path);
 	btrfs_free_path(path);
 	if (ret)
-		return ERR_PTR(ret);
+		goto bad_inode;
 
 	unlock_new_inode(&inode->vfs_inode);
 	return inode;
+
+bad_inode:
+	iget_failed(&inode->vfs_inode);
+	return ERR_PTR(ret);
 }
 
 static struct btrfs_inode *new_simple_dir(struct inode *dir,
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2025-04-22  4:09 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-21 10:32 [PATCH] btrfs: fix the resource leak issue in btrfs_iget() Penglei Jiang
2025-04-21 10:42 ` Qu Wenruo
2025-04-21 15:40   ` [PATCH v2] " Penglei Jiang
2025-04-21 20:12     ` Qu Wenruo
2025-04-22  4:09     ` Qu Wenruo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox