]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
libxfs: don't leave dangling perag references from xfs_buf
authorDarrick J. Wong <djwong@kernel.org>
Fri, 25 Feb 2022 22:32:48 +0000 (17:32 -0500)
committerEric Sandeen <sandeen@sandeen.net>
Fri, 25 Feb 2022 22:32:48 +0000 (17:32 -0500)
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 <djwong@kernel.org>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
libxfs/rdwr.c

index e26f725e181a7aefa5d7e19726f7dd0af75f2c96..4f1f5f10b9da5df8062666aeaf79f473984e8917 100644 (file)
@@ -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++;
        }