Skip to contentSkip to conversation

btrfs: fix a memory leak in read_zone_info

PATCH In review Christoph Hellwig 3 participants 3 messages Jul 4, 2022 – Jul 8, 2022 Btrfs file system

lore
Share & tools
lore
#0 lore raw

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")
---
 fs/btrfs/zoned.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
fs/btrfs/zoned.c +8 -4
index 7a0f8fa448006..46e6c70217e08 100644
@@ -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
Reviewed-by on v1 1/1
#1 lore raw
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")
Quoted 36 lines
---
  fs/btrfs/zoned.c | 12 ++++++++----
  1 file changed, 8 insertions(+), 4 deletions(-)
fs/btrfs/zoned.c +8 -4
index 7a0f8fa448006..46e6c70217e08 100644
@@ -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;
  }