[PATCH v3 0/2] hfsplus, hfs: fix B-tree node leak on hfs_btree_open() error path

From: Mahmut Emin Kurhan

Date: Thu Oct 01 2026 - 17:38:29 EST


This is v3 of the hfsplus/hfs B-tree node leak fix, rebased onto the
for-next branch of the HFS/HFS+ tree as requested.

The leak is unchanged: hfs_btree_open() can fail after the head node has
been inserted into tree->node_hash, and the error path does a bare
kfree(tree) without freeing the hashed nodes. The fix factors the
node-hash freeing out of hfs_btree_close() into hfs_bnode_hash_free() and
calls it from both hfs_btree_close() and the hfs_btree_open() error path.

Changes since v2:
- rebased on for-next; the extracted helper now wraps the hash_lock
serialized close loop introduced by commit dce0e0248205 ("hfs/hfsplus:
serialize B-tree close against folio release") (Slava Dubeyko)
- on the open error path the tree is not published yet, so the lock is
uncontended but kept for consistency
- no functional change to the leak fix itself

v2: https://lore.kernel.org/linux-fsdevel/20260930232312.1405042-1-guvenlik@xxxxxxxxxx

Mahmut Emin Kurhan (2):
hfsplus: free cached B-tree nodes on hfs_btree_open() error path
hfs: free cached B-tree nodes on hfs_btree_open() error path

fs/hfs/btree.c | 40 +++++++++++++++++++++++-----------------
fs/hfsplus/btree.c | 41 +++++++++++++++++++++++------------------
2 files changed, 46 insertions(+), 35 deletions(-)

--
2.43.0