diff mbox series

[v3,1/3] btrfs: block-group: Fix a memory leak due to missing btrfs_put_block_group()

Message ID 20191010023928.24586-2-wqu@suse.com (mailing list archive)
State New, archived
Headers show
Series btrfs: Introduce new incompat feature BG_TREE to hugely reduce mount time | expand

Commit Message

Qu Wenruo Oct. 10, 2019, 2:39 a.m. UTC
In btrfs_read_block_groups(), if we have an invalid block group which
has mixed type (DATA|METADATA) while the fs doesn't have MIX_BGS
feature, we error out without freeing the block group cache.

This patch will add the missing btrfs_put_block_group() to prevent
memory leak.

Fixes: 49303381f19a ("Btrfs: bail out if block group has different mixed flag")
Signed-off-by: Qu Wenruo <wqu@suse.com>
---
 fs/btrfs/block-group.c | 1 +
 1 file changed, 1 insertion(+)

Comments

Anand Jain Oct. 10, 2019, 2:51 a.m. UTC | #1
On 10/10/19 10:39 AM, Qu Wenruo wrote:
> In btrfs_read_block_groups(), if we have an invalid block group which
> has mixed type (DATA|METADATA) while the fs doesn't have MIX_BGS
> feature, we error out without freeing the block group cache.
> 
> This patch will add the missing btrfs_put_block_group() to prevent
> memory leak.
> 
> Fixes: 49303381f19a ("Btrfs: bail out if block group has different mixed flag")
> Signed-off-by: Qu Wenruo <wqu@suse.com>

Reviewed-by: Anand Jain <anand.jain@oracle.com>
Johannes Thumshirn Oct. 10, 2019, 7:20 a.m. UTC | #2
Reviewed-by: Johannes Thumshirn <jthumshirn@suse.de>
David Sterba Oct. 11, 2019, 7:23 p.m. UTC | #3
On Thu, Oct 10, 2019 at 10:39:26AM +0800, Qu Wenruo wrote:
> In btrfs_read_block_groups(), if we have an invalid block group which
> has mixed type (DATA|METADATA) while the fs doesn't have MIX_BGS
> feature, we error out without freeing the block group cache.
> 
> This patch will add the missing btrfs_put_block_group() to prevent
> memory leak.
> 
> Fixes: 49303381f19a ("Btrfs: bail out if block group has different mixed flag")
> Signed-off-by: Qu Wenruo <wqu@suse.com>

Please send independent fixes out of feature patchsets so it does not
get lost due to priorities fixes vs features. I'll add it to misc-next
and queue for 5.4. Thanks.
diff mbox series

Patch

diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
index bf7e3f23bba7..c906a2b6c2cf 100644
--- a/fs/btrfs/block-group.c
+++ b/fs/btrfs/block-group.c
@@ -1762,6 +1762,7 @@  int btrfs_read_block_groups(struct btrfs_fs_info *info)
 "bg %llu is a mixed block group but filesystem hasn't enabled mixed block groups",
 				  cache->key.objectid);
 			ret = -EINVAL;
+			btrfs_put_block_group(cache);
 			goto error;
 		}