From 22a693224bf7e473ff5fd8efe4cefaaf74217157 Mon Sep 17 00:00:00 2001 From: "Darrick J. Wong" Date: Tue, 25 Oct 2016 12:47:13 +1100 Subject: [PATCH] xfs: rework refcount cow recovery error handling Source kernel commit: 6f97077ff6ef28e0f3b361b6ba9c95a222ef384b The error handling in xfs_refcount_recover_cow_leftovers is confused and can potentially leak memory, so rework it to release resources correctly on error. Signed-off-by: Darrick J. Wong Reported-by: Brian Foster Reviewed-by: Dave Chinner Signed-off-by: Dave Chinner --- libxfs/xfs_refcount.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/libxfs/xfs_refcount.c b/libxfs/xfs_refcount.c index 4a223ed25..0508ec345 100644 --- a/libxfs/xfs_refcount.c +++ b/libxfs/xfs_refcount.c @@ -1642,7 +1642,7 @@ xfs_refcount_recover_cow_leftovers( error = xfs_btree_query_range(cur, &low, &high, xfs_refcount_recover_extent, &debris); if (error) - goto out_error; + goto out_cursor; xfs_btree_del_cursor(cur, XFS_BTREE_NOERROR); xfs_buf_relse(agbp); @@ -1674,14 +1674,8 @@ xfs_refcount_recover_cow_leftovers( error = xfs_trans_commit(tp); if (error) - goto out_cancel; + goto out_free; } - goto out_free; - -out_defer: - xfs_defer_cancel(&dfops); -out_cancel: - xfs_trans_cancel(tp); out_free: /* Free the leftover list */ @@ -1689,11 +1683,15 @@ out_free: list_del(&rr->rr_list); kmem_free(rr); } - return error; -out_error: +out_cursor: xfs_btree_del_cursor(cur, XFS_BTREE_ERROR); xfs_buf_relse(agbp); - return error; + goto out_free; + +out_defer: + xfs_defer_cancel(&dfops); + xfs_trans_cancel(tp); + goto out_free; } -- 2.47.2