From nobody Mon Feb 9 10:57:43 2026 Received: from mail-m49198.qiye.163.com (mail-m49198.qiye.163.com [45.254.49.198]) (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 1536C2F49F0; Thu, 25 Dec 2025 10:27:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.254.49.198 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766658457; cv=none; b=VdKEY1oCl/S3PT6GzPifZi6EuAt9UwVBXgqBo8N0u6RgKNoka8K/9TVvq7h/CSY+QRLXeMG8AbaZ3HkAlnNpA98Czt7Ck5Xx84ZajuDV6aUGKer81PaH1aXKt3BxFSBF3ayVpsiJdO8dXaHsI5IOBgrYff8lfAhX3vQI9EggOiQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766658457; c=relaxed/simple; bh=kcxm1mHC2AHWepF9LVrufs5Vd2CCt+oDM36bSQRdspU=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=Rk0OTZlYok406VvmlnVAT/nqgYDzf37UHOoDWIk13ic+3TzctCR/JILFZejp5WZNAE8i3l64mtQZwkNGVdO+iejJl4ML2YzekCNC9p7Jah7dPBa/CIw+j6EGSxYuuGjQ3xEMR1KpSc2RoggIFkPIUen8BB8jWbMv/fZhe1zA5W8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=seu.edu.cn; spf=pass smtp.mailfrom=seu.edu.cn; dkim=pass (1024-bit key) header.d=seu.edu.cn header.i=@seu.edu.cn header.b=BC89Zrp9; arc=none smtp.client-ip=45.254.49.198 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=seu.edu.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=seu.edu.cn Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=seu.edu.cn header.i=@seu.edu.cn header.b="BC89Zrp9" Received: from LAPTOP-N070L597.localdomain (unknown [58.241.16.34]) by smtp.qiye.163.com (Hmail) with ESMTP id 2e8b969cf; Thu, 25 Dec 2025 18:27:29 +0800 (GMT+08:00) From: Zilin Guan To: clm@fb.com Cc: dsterba@suse.com, sunk67188@gmail.com, dan.carpenter@linaro.org, linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org, jianhao.xu@seu.edu.cn, Zilin Guan Subject: [PATCH] btrfs: tests: Fix memory leak in btrfs_test_qgroups() Date: Thu, 25 Dec 2025 10:27:27 +0000 Message-Id: <20251225102727.967360-1-zilin@seu.edu.cn> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-HM-Tid: 0a9b550ca04403a1kunm3d3657943c873 X-HM-MType: 10 X-HM-Spam-Status: e1kfGhgUHx5ZQUtXWQgPGg8OCBgUHx5ZQUlOS1dZFg8aDwILHllBWSg2Ly tZV1koWUFITzdXWS1ZQUlXWQ8JGhUIEh9ZQVkaQ05OVk1CSEpNSB1JSUseTVYeHw5VEwETFhoSFy QUDg9ZV1kYEgtZQVlOQ1VJT0pVSk1VSE9ZV1kWGg8SFR0UWUFZS1VLVUtVS1kG DKIM-Signature: a=rsa-sha256; b=BC89Zrp9QQRDw2fh648sIke0ofJxDAJK/j/N618/kAJyWPSi5x/0q1dsPosTmIGa8+miHrUofVzaX2/eyErOhZIAdwm0VMtC4nDhekEYcVna9mGv1E3ddRMDYPYVY4MBthm/H20LF0SHsZR80wB41xa54d9ciKo8tiFwjW1/46c=; c=relaxed/relaxed; s=default; d=seu.edu.cn; v=1; bh=xMumdwLGnzfooVex7fPc5gc9CljbwqfTQRSpLl35PKU=; h=date:mime-version:subject:message-id:from; Content-Type: text/plain; charset="utf-8" btrfs_alloc_dummy_root() allocates a root with a reference count of 1. Then btrfs_insert_fs_root() is used to insert the root into the fs_info. On success, it increments the reference count. On failure, it does not. Currently, if btrfs_insert_fs_root() fails, the error handling path jumps to the out label immediately without decrementing the reference count of tmp_root, leading to a memory leak. Fix this by calling btrfs_put_root() unconditionally after btrfs_insert_fs_root(). This correctly handles both cases: on success, it drops the local reference, leaving the root with the reference held by fs_info; on failure, it drops the sole reference, freeing the root. Fixes: 4785e24fa5d23 ("btrfs: don't take an extra root ref at allocation ti= me") Signed-off-by: Zilin Guan --- fs/btrfs/tests/qgroup-tests.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/tests/qgroup-tests.c b/fs/btrfs/tests/qgroup-tests.c index e9124605974b..0d51e0abaeac 100644 --- a/fs/btrfs/tests/qgroup-tests.c +++ b/fs/btrfs/tests/qgroup-tests.c @@ -517,11 +517,11 @@ int btrfs_test_qgroups(u32 sectorsize, u32 nodesize) tmp_root->root_key.objectid =3D BTRFS_FS_TREE_OBJECTID; root->fs_info->fs_root =3D tmp_root; ret =3D btrfs_insert_fs_root(root->fs_info, tmp_root); + btrfs_put_root(tmp_root); if (ret) { test_err("couldn't insert fs root %d", ret); goto out; } - btrfs_put_root(tmp_root); =20 tmp_root =3D btrfs_alloc_dummy_root(fs_info); if (IS_ERR(tmp_root)) { @@ -532,11 +532,11 @@ int btrfs_test_qgroups(u32 sectorsize, u32 nodesize) =20 tmp_root->root_key.objectid =3D BTRFS_FIRST_FREE_OBJECTID; ret =3D btrfs_insert_fs_root(root->fs_info, tmp_root); + btrfs_put_root(tmp_root); if (ret) { test_err("couldn't insert fs root %d", ret); goto out; } - btrfs_put_root(tmp_root); =20 test_msg("running qgroup tests"); ret =3D test_no_shared_qgroup(root, sectorsize, nodesize); --=20 2.34.1