dm persistent data: don't leak bufio buffer if find_leaf fails
Mikulas Patocka
maintainerPATCH 1/1 dm persistent data: don't leak bufio buffer if find_leaf fails
If find_leaf fails, the function dm_btree_cursor_begin would return an error, but it would keep the dm-bufio buffers held. This would result in a memory leak and a warning when releasing the dm-bufio cache.
This commit fixes it, so that dm_btree_cursor_begin releases the buffers on error.
Signed-off-by Mikulas Patocka <[email protected]>
Assisted-by Claude:claude-opus-5
Fixes 7d111c81fa29 ("dm btree: introduce cursor api")
--- drivers/md/persistent-data/dm-btree.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/md/persistent-data/dm-btree.c +7 -1
@@ -1582,7 +1582,13 @@ int dm_btree_cursor_begin(struct dm_btreif (r)return r; -return find_leaf (c); + r =find_leaf (c); +if (unlikely (r)) { +dm_btree_cursor_end (c); +return r; + } + +return 0 ; }EXPORT_SYMBOL_GPL (dm_btree_cursor_begin);