Skip to content

Commit

Permalink
xfs: rework refcount cow recovery error handling
Browse files Browse the repository at this point in the history
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 <darrick.wong@oracle.com>
Reported-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
  • Loading branch information
Darrick J. Wong authored and Dave Chinner committed Oct 10, 2016
1 parent 1987fd7 commit 6f97077
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions fs/xfs/libxfs/xfs_refcount.c
Original file line number Diff line number Diff line change
Expand Up @@ -1643,7 +1643,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);

Expand Down Expand Up @@ -1675,26 +1675,24 @@ 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 */
list_for_each_entry_safe(rr, n, &debris, rr_list) {
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;
}

0 comments on commit 6f97077

Please sign in to comment.