blob: 1c0251bc21ef917148c68aec36bbed576afba95c [file] [log] [blame]
From 9e55f1f1d97b90a3c825c0eac1fcc44512bfc929 Mon Sep 17 00:00:00 2001
From: Qu Wenruo <>
Date: Thu, 10 Oct 2019 10:39:26 +0800
Subject: [PATCH] btrfs: block-group: Fix a memory leak due to missing
commit 4b654acdae850f48b8250b9a578a4eaa518c7a6f upstream.
In btrfs_read_block_groups(), if we have an invalid block group which
has mixed type (DATA|METADATA) while the fs doesn't have MIXED_GROUPS
feature, we error out without freeing the block group cache.
This patch will add the missing btrfs_put_block_group() to prevent
memory leak.
Note for stable backports: the file to patch in versions <= 5.3 is
Fixes: 49303381f19a ("Btrfs: bail out if block group has different mixed flag")
CC: # 4.9+
Reviewed-by: Anand Jain <>
Reviewed-by: Johannes Thumshirn <>
Signed-off-by: Qu Wenruo <>
Reviewed-by: David Sterba <>
Signed-off-by: David Sterba <>
[PG: adapt for different file name in older code base.]
Signed-off-by: Paul Gortmaker <>
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index 37865929fdc2..6c1b7ec3b9ff 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -10374,6 +10374,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",
+ btrfs_put_block_group(cache);
ret = -EINVAL;
goto error;