]> git-server-git.apps.pok.os.sepia.ceph.com Git - xfsprogs-dev.git/commitdiff
libxfs: don't leave dangling perag references from xfs_buf
authorDarrick J. Wong <djwong@kernel.org>
Thu, 6 Jan 2022 22:13:17 +0000 (14:13 -0800)
committerDarrick J. Wong <djwong@kernel.org>
Thu, 20 Jan 2022 00:02:51 +0000 (16:02 -0800)
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>
libxfs/rdwr.c

index 2a9e8c9848889d215640c2282b01e62644a125d0..b43527e465443dcdebe13b63ac97034b6653d1d8 100644 (file)
@@ -887,11 +887,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);
 
@@ -909,11 +917,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);
@@ -932,8 +936,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++;
        }