[5/5] btrfs: do not leak reloc root if we fail to read the fs root
diff mbox series

Message ID 20191206143718.167998-6-josef@toxicpanda.com
State New
Headers show
Series
  • Various fixes
Related show

Commit Message

Josef Bacik Dec. 6, 2019, 2:37 p.m. UTC
If we fail to read the fs root corresponding with a reloc root we'll
just break out and free the reloc roots.  But we remove our current
reloc_root from this list higher up, which means we'll leak this
reloc_root.  Fix this by adding ourselves back to the reloc_roots list
so we are properly cleaned up.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/btrfs/relocation.c | 1 +
 1 file changed, 1 insertion(+)

Comments

Filipe Manana Dec. 6, 2019, 3:24 p.m. UTC | #1
On Fri, Dec 6, 2019 at 2:39 PM Josef Bacik <josef@toxicpanda.com> wrote:
>
> If we fail to read the fs root corresponding with a reloc root we'll
> just break out and free the reloc roots.  But we remove our current
> reloc_root from this list higher up, which means we'll leak this
> reloc_root.  Fix this by adding ourselves back to the reloc_roots list
> so we are properly cleaned up.
>
> Signed-off-by: Josef Bacik <josef@toxicpanda.com>

Reviewed-by: Filipe Manana <fdmanana@suse.com>

Looks good, thanks.

> ---
>  fs/btrfs/relocation.c | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
> index a857fc8271d2..c5fcddad1c15 100644
> --- a/fs/btrfs/relocation.c
> +++ b/fs/btrfs/relocation.c
> @@ -4554,6 +4554,7 @@ int btrfs_recover_relocation(struct btrfs_root *root)
>                 fs_root = read_fs_root(fs_info, reloc_root->root_key.offset);
>                 if (IS_ERR(fs_root)) {
>                         err = PTR_ERR(fs_root);
> +                       list_add_tail(&reloc_root->root_list, &reloc_roots);
>                         goto out_free;
>                 }
>
> --
> 2.23.0
>
Johannes Thumshirn Dec. 9, 2019, 10:58 a.m. UTC | #2
Looks good,
Reviewed-by: Johannes Thumshirn <jthumshirn@suse.de>

Patch
diff mbox series

diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
index a857fc8271d2..c5fcddad1c15 100644
--- a/fs/btrfs/relocation.c
+++ b/fs/btrfs/relocation.c
@@ -4554,6 +4554,7 @@  int btrfs_recover_relocation(struct btrfs_root *root)
 		fs_root = read_fs_root(fs_info, reloc_root->root_key.offset);
 		if (IS_ERR(fs_root)) {
 			err = PTR_ERR(fs_root);
+			list_add_tail(&reloc_root->root_list, &reloc_roots);
 			goto out_free;
 		}