From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9425C36C0CE; Wed, 28 Jan 2026 15:27:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769614058; cv=none; b=svHWCjnhZfoC0ZadDYKlXIrBb0hzhhyvHYzswrPE8mK8fHDyNWBFg9UF0XFAIRCE5QIMJrXhgwbBZltkXMq3r9k5MNHQJxcJ8EWsN28KPXvH4MYQbgZ3MycKpJRzFvNZZAIdCEtTIckW6DbompFgIvEVqoyDNNFYMcCW61pkAoY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769614058; c=relaxed/simple; bh=5asWBJc3TKKyRXBziITpKSE5TOHtZ02USWUJKUqkmT4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lr0BBkAP/ajSK36LBGXaPvPvVjQsNPd08DzrgLdPnwNdOPVyDhasvAStwelEf0jcU5jUKXBnOBseHrLHVLBzzXnn0lqnEaDP8Wj/ir6dbq75iKNYWu3gkP4jwtjzYBaxlvtPNz28sd1XU85p/UF7kDYBIYMEJQBK0vinag8mokU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=kYQeWa2k; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="kYQeWa2k" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8E69EC4CEF1; Wed, 28 Jan 2026 15:27:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1769614058; bh=5asWBJc3TKKyRXBziITpKSE5TOHtZ02USWUJKUqkmT4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kYQeWa2kBXpfBl06sFGTHYO2QMvd3Vs2sastTsRK4lijMVN0/sgoE3TsR7DZxUXzd xemuudkggZ6JJ+m6nvGpLje74dEjtrLvDRtE30cccO5bgAPtFmDjONFTy/WMcsvh6b qKwySY28dnQbaCSwyZoLzvJWlz/J/BMDmbXpWoA4= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Qu Wenruo , Jiasheng Jiang , David Sterba , Sasha Levin Subject: [PATCH 6.6 023/254] btrfs: fix memory leaks in create_space_info() error paths Date: Wed, 28 Jan 2026 16:19:59 +0100 Message-ID: <20260128145345.539488702@linuxfoundation.org> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260128145344.698118637@linuxfoundation.org> References: <20260128145344.698118637@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Jiasheng Jiang [ 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 Signed-off-by: Jiasheng Jiang Signed-off-by: David Sterba Signed-off-by: Sasha Levin --- fs/btrfs/space-info.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/space-info.c b/fs/btrfs/space-info.c index 01d9a93346c28..00d596a8176ff 100644 --- a/fs/btrfs/space-info.c +++ b/fs/btrfs/space-info.c @@ -288,18 +288,22 @@ static int create_space_info(struct btrfs_fs_info *info, u64 flags) BTRFS_SUB_GROUP_DATA_RELOC, 0); if (ret) - return ret; + goto out_free; } ret = btrfs_sysfs_add_space_info_type(info, space_info); if (ret) - return ret; + goto out_free; list_add(&space_info->list, &info->space_info); if (flags & BTRFS_BLOCK_GROUP_DATA) info->data_sinfo = space_info; return ret; + +out_free: + kfree(space_info); + return ret; } int btrfs_init_space_info(struct btrfs_fs_info *fs_info) -- 2.51.0