]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
btrfs: fix memory leaks in create_space_info() error paths
authorJiasheng Jiang <jiashengjiangcool@gmail.com>
Sun, 11 Jan 2026 19:20:37 +0000 (19:20 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 23 Jan 2026 10:18:38 +0000 (11:18 +0100)
commitbb4fa4c0b54aae25e55faeda7f78d0c11b8cd618
tree4db05d27e7bfb86499ee377405af3edbbd25d09a
parent190d5a7c4fe42b8c9aa46e3336389e7cb10395bb
btrfs: fix memory leaks in create_space_info() error paths

[ Upstream commit a11224a016d6d1d46a4d9b6573244448a80d4d7f ]

In create_space_info(), the 'space_info' object is allocated at the
beginning of the function. However, there are two error paths where the
function returns an error code without freeing the allocated memory:

1. When create_space_info_sub_group() fails in zoned mode.
2. When btrfs_sysfs_add_space_info_type() fails.

In both cases, 'space_info' has not yet been added to the
fs_info->space_info list, resulting in a memory leak. Fix this by
adding an error handling label to kfree(space_info) before returning.

Fixes: 2be12ef79fe9 ("btrfs: Separate space_info create/update")
Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Jiasheng Jiang <jiashengjiangcool@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
fs/btrfs/space-info.c