Skip to contentSkip to conversation

btrfs: fix a memory leak in read_zone_info

PATCH In review Christoph Hellwig 4 participants 7 messages Jun 30, 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.

Fixes 7db1c5d14dcd ("btrfs: zoned: support dev-replace in zoned filesystems")
---
 fs/btrfs/zoned.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/btrfs/zoned.c +1 -1
index 7a0f8fa448006..e92bd5582cab3 100644
@@ -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;
 }
 
Signature · 1 line
2.30.2
#2 lore raw
In reply to Christoph Hellwig
Quoted 13 lines · Christoph Hellwig

Don't leak the bioc on normal completion.

Fixes 7db1c5d14dcd ("btrfs: zoned: support dev-replace in zoned filesystems")
---
  fs/btrfs/zoned.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
fs/btrfs/zoned.c +0 -0
index 7a0f8fa448006..e92bd5582cab3 100644

fs/btrfs/zoned.c static int read_zone_info(struct btrfs_fs_info *fs_info, u64 logical, · line 1765

Quoted 8 lines
fs/btrfs/zoned.c +1 -1
@@ -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

#3 lore raw
Quoted 25 lines · Anand Jain
Quoted 13 lines · Christoph Hellwig

Don't leak the bioc on normal completion.

Fixes 7db1c5d14dcd ("btrfs: zoned: support dev-replace in zoned filesystems")
---
  fs/btrfs/zoned.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
fs/btrfs/zoned.c +0 -0
index 7a0f8fa448006..e92bd5582cab3 100644

fs/btrfs/zoned.c static int read_zone_info(struct btrfs_fs_info *fs_info, u64 logical, · line 1765

Quoted 8 lines
fs/btrfs/zoned.c +1 -1
@@ -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?

Quoted 2 lines

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.

#4 lore raw
Quoted 3 lines · David Sterba

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.

#5 lore raw
Quoted 7 lines · Christoph Hellwig
Quoted 3 lines · David Sterba

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.