diff mbox series

btrfs: fix a memory leak in read_zone_info

Message ID 20220630160319.2550384-1-hch@lst.de (mailing list archive)
State New, archived
Headers show
Series btrfs: fix a memory leak in read_zone_info | expand

Commit Message

Christoph Hellwig June 30, 2022, 4:03 p.m. UTC
Don't leak the bioc on normal completion.

Fixes: 7db1c5d14dcd ("btrfs: zoned: support dev-replace in zoned filesystems")
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 fs/btrfs/zoned.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Johannes Thumshirn July 1, 2022, 5:59 a.m. UTC | #1
Looks good,
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Anand Jain July 3, 2022, 1:41 a.m. UTC | #2
On 01/07/2022 00:03, Christoph Hellwig wrote:
> Don't leak the bioc on normal completion.
> 
> Fixes: 7db1c5d14dcd ("btrfs: zoned: support dev-replace in zoned filesystems")
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
>   fs/btrfs/zoned.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c
> index 7a0f8fa448006..e92bd5582cab3 100644
> --- a/fs/btrfs/zoned.c
> +++ b/fs/btrfs/zoned.c
> @@ -1759,7 +1759,7 @@ static int read_zone_info(struct btrfs_fs_info *fs_info, u64 logical,
>   		break;
>   	}
>   	memalloc_nofs_restore(nofs_flag);
> -
> +	btrfs_put_bioc(bioc);
>   	return ret;
>   }
>   

Why not call put also during return -EINVAL a few lines above?

  if (bioc->map_type & BTRFS_BLOCK_GROUP_RAID56_MASK)
	 return -EINVAL;

-Anand
David Sterba July 7, 2022, 5:19 p.m. UTC | #3
On Thu, Jun 30, 2022 at 06:03:19PM +0200, Christoph Hellwig wrote:
> Don't leak the bioc on normal completion.
> 
> Fixes: 7db1c5d14dcd ("btrfs: zoned: support dev-replace in zoned filesystems")
> Signed-off-by: Christoph Hellwig <hch@lst.de>

Added to misc-next, thanks.
David Sterba July 7, 2022, 5:22 p.m. UTC | #4
On Sun, Jul 03, 2022 at 09:41:07AM +0800, Anand Jain wrote:
> On 01/07/2022 00:03, Christoph Hellwig wrote:
> > Don't leak the bioc on normal completion.
> > 
> > Fixes: 7db1c5d14dcd ("btrfs: zoned: support dev-replace in zoned filesystems")
> > Signed-off-by: Christoph Hellwig <hch@lst.de>
> > ---
> >   fs/btrfs/zoned.c | 2 +-
> >   1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c
> > index 7a0f8fa448006..e92bd5582cab3 100644
> > --- a/fs/btrfs/zoned.c
> > +++ b/fs/btrfs/zoned.c
> > @@ -1759,7 +1759,7 @@ static int read_zone_info(struct btrfs_fs_info *fs_info, u64 logical,
> >   		break;
> >   	}
> >   	memalloc_nofs_restore(nofs_flag);
> > -
> > +	btrfs_put_bioc(bioc);
> >   	return ret;
> >   }
> >   
> 
> Why not call put also during return -EINVAL a few lines above?
> 
>   if (bioc->map_type & BTRFS_BLOCK_GROUP_RAID56_MASK)
> 	 return -EINVAL;

Actually yes, it should be here as well, otherwise this would leak.
RAID56 + zoned combination is rejected much earlier so this would not
happen in practice.
Christoph Hellwig July 7, 2022, 5:34 p.m. UTC | #5
On Thu, Jul 07, 2022 at 07:22:41PM +0200, David Sterba wrote:
> Actually yes, it should be here as well, otherwise this would leak.
> RAID56 + zoned combination is rejected much earlier so this would not
> happen in practice.

A version with that fixed is already out on the list, just pick that
one up instead.
David Sterba July 8, 2022, 12:46 p.m. UTC | #6
On Thu, Jul 07, 2022 at 07:34:03PM +0200, Christoph Hellwig wrote:
> On Thu, Jul 07, 2022 at 07:22:41PM +0200, David Sterba wrote:
> > Actually yes, it should be here as well, otherwise this would leak.
> > RAID56 + zoned combination is rejected much earlier so this would not
> > happen in practice.
> 
> A version with that fixed is already out on the list, just pick that
> one up instead.

Right, I did not notice it.
diff mbox series

Patch

diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c
index 7a0f8fa448006..e92bd5582cab3 100644
--- a/fs/btrfs/zoned.c
+++ b/fs/btrfs/zoned.c
@@ -1759,7 +1759,7 @@  static int read_zone_info(struct btrfs_fs_info *fs_info, u64 logical,
 		break;
 	}
 	memalloc_nofs_restore(nofs_flag);
-
+	btrfs_put_bioc(bioc);
 	return ret;
 }