From: Darrick J. Wong Date: Fri, 25 Feb 2022 22:32:48 +0000 (-0500) Subject: libxfs: don't leave dangling perag references from xfs_buf X-Git-Tag: v5.15.0-rc1~21 X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=4bac42bac6c8a797a93966e656a95750d5656663;p=thirdparty%2Fxfsprogs-dev.git libxfs: don't leave dangling perag references from xfs_buf When we're preparing to move a list of xfs_buf(fers) to the freelist, be sure to detach the perag reference so that we don't leak the reference or leave dangling pointers. Currently this has no negative effects since we only call libxfs_bulkrelse while exiting programs, but let's not be sloppy. Signed-off-by: Darrick J. Wong Reviewed-by: Eric Sandeen Signed-off-by: Eric Sandeen --- diff --git a/libxfs/rdwr.c b/libxfs/rdwr.c index e26f725e1..4f1f5f10b 100644 --- a/libxfs/rdwr.c +++ b/libxfs/rdwr.c @@ -890,11 +890,19 @@ libxfs_buf_mark_dirty( bp->b_flags |= LIBXFS_B_DIRTY; } -/* Complain about (and remember) dropping dirty buffers. */ -static void -libxfs_whine_dirty_buf( +/* Prepare a buffer to be sent to the MRU list. */ +static inline void +libxfs_buf_prepare_mru( struct xfs_buf *bp) { + if (bp->b_pag) + xfs_perag_put(bp->b_pag); + bp->b_pag = NULL; + + if (!(bp->b_flags & LIBXFS_B_DIRTY)) + return; + + /* Complain about (and remember) dropping dirty buffers. */ fprintf(stderr, _("%s: Releasing dirty buffer to free list!\n"), progname); @@ -912,11 +920,7 @@ libxfs_brelse( if (!bp) return; - if (bp->b_flags & LIBXFS_B_DIRTY) - libxfs_whine_dirty_buf(bp); - if (bp->b_pag) - xfs_perag_put(bp->b_pag); - bp->b_pag = NULL; + libxfs_buf_prepare_mru(bp); pthread_mutex_lock(&xfs_buf_freelist.cm_mutex); list_add(&bp->b_node.cn_mru, &xfs_buf_freelist.cm_list); @@ -935,8 +939,7 @@ libxfs_bulkrelse( return 0 ; list_for_each_entry(bp, list, b_node.cn_mru) { - if (bp->b_flags & LIBXFS_B_DIRTY) - libxfs_whine_dirty_buf(bp); + libxfs_buf_prepare_mru(bp); count++; }