btrfs: fix a memory leak in read_zone_info
PATCH 1/1 btrfs: fix a memory leak in read_zone_info
Don't leak the bioc on normal completion or when finding a parity raid extent.
Fixes 7db1c5d14dcd ("btrfs: zoned: support dev-replace in zoned filesystems")
Signed-off-by Christoph Hellwig <[email protected]>
--- fs/btrfs/zoned.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
fs/btrfs/zoned.c +8 -4
@@ -1735,12 +1735,14 @@ static int read_zone_info(struct btrfs_fs_info *fs_info, u64 logical, ret =btrfs_map_sblock (fs_info,BTRFS_MAP_GET_READ_MIRRORS , logical, &mapped_length, &bioc);if (ret || !bioc || mapped_length <PAGE_SIZE ) { -btrfs_put_bioc (bioc); -return -EIO ; + ret = -EIO ; + goto out_put_bioc; } -if (bioc->map_type &BTRFS_BLOCK_GROUP_RAID56_MASK ) -return -EINVAL ; +if (bioc->map_type &BTRFS_BLOCK_GROUP_RAID56_MASK ) { + ret = -EINVAL ; + goto out_put_bioc; + } nofs_flag =memalloc_nofs_save (); nmirrors = (int )bioc->num_stripes;
@@ -1760,6 +1762,8 @@ static int read_zone_info(struct btrfs_fs_info *fs_info, u64 logical, }memalloc_nofs_restore (nofs_flag); +out_put_bioc: +btrfs_put_bioc (bioc);return ret; }
Signature · 1 line
2.30.2
Quoted 5 lines · Christoph Hellwig
Don't leak the bioc on normal completion or when finding a parity raid extent.
Fixes 7db1c5d14dcd ("btrfs: zoned: support dev-replace in zoned filesystems")Signed-off-by Christoph Hellwig <[email protected]>
Reviewed-by Anand Jain <[email protected]>
Quoted 36 lines
--- fs/btrfs/zoned.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)fs/btrfs/zoned.c +8
-4@@ -1735,12 +1735,14 @@ static int read_zone_info(struct btrfs_fs_info *fs_info, u64 logical, ret =btrfs_map_sblock (fs_info,BTRFS_MAP_GET_READ_MIRRORS , logical, &mapped_length, &bioc);if (ret || !bioc || mapped_length <PAGE_SIZE ) { -btrfs_put_bioc (bioc); -return -EIO ; + ret = -EIO ; + goto out_put_bioc; } -if (bioc->map_type &BTRFS_BLOCK_GROUP_RAID56_MASK ) -return -EINVAL ; +if (bioc->map_type &BTRFS_BLOCK_GROUP_RAID56_MASK ) { + ret = -EINVAL ; + goto out_put_bioc; + } nofs_flag =memalloc_nofs_save (); nmirrors = (int )bioc->num_stripes;@@ -1760,6 +1762,8 @@ static int read_zone_info(struct btrfs_fs_info *fs_info, u64 logical, }memalloc_nofs_restore (nofs_flag); +out_put_bioc: +btrfs_put_bioc (bioc);return ret; }
Quoted 5 lines · Christoph Hellwig
Don't leak the bioc on normal completion or when finding a parity raid extent.
Fixes 7db1c5d14dcd ("btrfs: zoned: support dev-replace in zoned filesystems")Signed-off-by Christoph Hellwig <[email protected]>
Added to misc-next, thanks.