mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] btrfs: fix memory leak in data_reloc_print_warning_inode()
@ 2025-11-05  2:37 Zilin Guan
  2025-11-05  9:14 ` Qu Wenruo
  0 siblings, 1 reply; 2+ messages in thread
From: Zilin Guan @ 2025-11-05  2:37 UTC (permalink / raw)
  To: clm; +Cc: dsterba, linux-btrfs, linux-kernel, jianhao.xu, Zilin Guan

data_reloc_print_warning_inode() calls btrfs_get_fs_root() to obtain
local_root, but fails to release its reference when paths_from_inode()
returns an error. This causes a potential memory leak.

Add a missing btrfs_put_root() call in the error path to properly
decrease the reference count of local_root.

Fixes: b9a9a85059cde ("btrfs: output affected files when relocation fails")
Signed-off-by: Zilin Guan <zilin@seu.edu.cn>
---
 fs/btrfs/inode.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 3df5f36185a0..6282911e536f 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -177,8 +177,10 @@ static int data_reloc_print_warning_inode(u64 inum, u64 offset, u64 num_bytes,
 		return ret;
 	}
 	ret = paths_from_inode(inum, ipath);
-	if (ret < 0)
+	if (ret < 0) {
+		btrfs_put_root(local_root);
 		goto err;
+	}
 
 	/*
 	 * We deliberately ignore the bit ipath might have been too small to
-- 
2.34.1


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

* Re: [PATCH] btrfs: fix memory leak in data_reloc_print_warning_inode()
  2025-11-05  2:37 [PATCH] btrfs: fix memory leak in data_reloc_print_warning_inode() Zilin Guan
@ 2025-11-05  9:14 ` Qu Wenruo
  0 siblings, 0 replies; 2+ messages in thread
From: Qu Wenruo @ 2025-11-05  9:14 UTC (permalink / raw)
  To: Zilin Guan, clm; +Cc: dsterba, linux-btrfs, linux-kernel, jianhao.xu



在 2025/11/5 13:07, Zilin Guan 写道:
> data_reloc_print_warning_inode() calls btrfs_get_fs_root() to obtain
> local_root, but fails to release its reference when paths_from_inode()
> returns an error. This causes a potential memory leak.
> 
> Add a missing btrfs_put_root() call in the error path to properly
> decrease the reference count of local_root.
> 
> Fixes: b9a9a85059cde ("btrfs: output affected files when relocation fails")
> Signed-off-by: Zilin Guan <zilin@seu.edu.cn>

Reviewed-by: Qu Wenruo <wqu@suse.com>

Now merged into for-next branch.

Thanks,
Qu

> ---
>   fs/btrfs/inode.c | 4 +++-
>   1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
> index 3df5f36185a0..6282911e536f 100644
> --- a/fs/btrfs/inode.c
> +++ b/fs/btrfs/inode.c
> @@ -177,8 +177,10 @@ static int data_reloc_print_warning_inode(u64 inum, u64 offset, u64 num_bytes,
>   		return ret;
>   	}
>   	ret = paths_from_inode(inum, ipath);
> -	if (ret < 0)
> +	if (ret < 0) {
> +		btrfs_put_root(local_root);
>   		goto err;
> +	}
>   
>   	/*
>   	 * We deliberately ignore the bit ipath might have been too small to


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

end of thread, other threads:[~2025-11-05  9:14 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-11-05  2:37 [PATCH] btrfs: fix memory leak in data_reloc_print_warning_inode() Zilin Guan
2025-11-05  9:14 ` Qu Wenruo

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

all inboxes | Powered by JetHome®