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
Cc: [email protected]
Fixes: 7d111c81fa29 ("dm btree: introduce cursor api")

---
 drivers/md/persistent-data/dm-btree.c |    8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

Index: linux-2.6/drivers/md/persistent-data/dm-btree.c
===================================================================
--- linux-2.6.orig/drivers/md/persistent-data/dm-btree.c
+++ linux-2.6/drivers/md/persistent-data/dm-btree.c
@@ -1582,7 +1582,13 @@ int dm_btree_cursor_begin(struct dm_btre
        if (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);
 


Reply via email to