Skip to content

Commit a54f78d

Browse files
Darrick J. Wongdchinner
authored andcommitted
xfs: don't leak btree cursor when insrec fails after a split
The recent patch to improve btree cycle checking caused a regression when I rebased the in-memory btree branch atop the 5.19 for-next branch, because in-memory short-pointer btrees do not have AG numbers. This produced the following complaint from kmemleak: unreferenced object 0xffff88803d47dde8 (size 264): comm "xfs_io", pid 4889, jiffies 4294906764 (age 24.072s) hex dump (first 32 bytes): 90 4d 0b 0f 80 88 ff ff 00 a0 bd 05 80 88 ff ff .M.............. e0 44 3a a0 ff ff ff ff 00 df 08 06 80 88 ff ff .D:............. backtrace: [<ffffffffa0388059>] xfbtree_dup_cursor+0x49/0xc0 [xfs] [<ffffffffa029887b>] xfs_btree_dup_cursor+0x3b/0x200 [xfs] [<ffffffffa029af5d>] __xfs_btree_split+0x6ad/0x820 [xfs] [<ffffffffa029b130>] xfs_btree_split+0x60/0x110 [xfs] [<ffffffffa029f6da>] xfs_btree_make_block_unfull+0x19a/0x1f0 [xfs] [<ffffffffa029fada>] xfs_btree_insrec+0x3aa/0x810 [xfs] [<ffffffffa029fff3>] xfs_btree_insert+0xb3/0x240 [xfs] [<ffffffffa02cb729>] xfs_rmap_insert+0x99/0x200 [xfs] [<ffffffffa02cf142>] xfs_rmap_map_shared+0x192/0x5f0 [xfs] [<ffffffffa02cf60b>] xfs_rmap_map_raw+0x6b/0x90 [xfs] [<ffffffffa0384a85>] xrep_rmap_stash+0xd5/0x1d0 [xfs] [<ffffffffa0384dc0>] xrep_rmap_visit_bmbt+0xa0/0xf0 [xfs] [<ffffffffa0384fb6>] xrep_rmap_scan_iext+0x56/0xa0 [xfs] [<ffffffffa03850d8>] xrep_rmap_scan_ifork+0xd8/0x160 [xfs] [<ffffffffa0385195>] xrep_rmap_scan_inode+0x35/0x80 [xfs] [<ffffffffa03852ee>] xrep_rmap_find_rmaps+0x10e/0x270 [xfs] I noticed that xfs_btree_insrec has a bunch of debug code that return out of the function immediately, without freeing the "new" btree cursor that can be returned when _make_block_unfull calls xfs_btree_split. Fix the error return in this function to free the btree cursor. Signed-off-by: Darrick J. Wong <djwong@kernel.org> Reviewed-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Dave Chinner <dchinner@redhat.com> Signed-off-by: Dave Chinner <david@fromorbit.com>
1 parent 86d40f1 commit a54f78d

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

fs/xfs/libxfs/xfs_btree.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3272,7 +3272,7 @@ xfs_btree_insrec(
32723272
struct xfs_btree_block *block; /* btree block */
32733273
struct xfs_buf *bp; /* buffer for block */
32743274
union xfs_btree_ptr nptr; /* new block ptr */
3275-
struct xfs_btree_cur *ncur; /* new btree cursor */
3275+
struct xfs_btree_cur *ncur = NULL; /* new btree cursor */
32763276
union xfs_btree_key nkey; /* new block key */
32773277
union xfs_btree_key *lkey;
32783278
int optr; /* old key/record index */
@@ -3352,7 +3352,7 @@ xfs_btree_insrec(
33523352
#ifdef DEBUG
33533353
error = xfs_btree_check_block(cur, block, level, bp);
33543354
if (error)
3355-
return error;
3355+
goto error0;
33563356
#endif
33573357

33583358
/*
@@ -3372,7 +3372,7 @@ xfs_btree_insrec(
33723372
for (i = numrecs - ptr; i >= 0; i--) {
33733373
error = xfs_btree_debug_check_ptr(cur, pp, i, level);
33743374
if (error)
3375-
return error;
3375+
goto error0;
33763376
}
33773377

33783378
xfs_btree_shift_keys(cur, kp, 1, numrecs - ptr + 1);
@@ -3457,6 +3457,8 @@ xfs_btree_insrec(
34573457
return 0;
34583458

34593459
error0:
3460+
if (ncur)
3461+
xfs_btree_del_cursor(ncur, error);
34603462
return error;
34613463
}
34623464

0 commit comments

Comments
 (0)