]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
libxfs: free resources in libxfs_alloc_file_space error paths
authorEric Sandeen <sandeen@sandeen.net>
Mon, 14 Apr 2014 06:13:05 +0000 (16:13 +1000)
committerDave Chinner <david@fromorbit.com>
Mon, 14 Apr 2014 06:13:05 +0000 (16:13 +1000)
The bmap freelist & transaction pointer weren't
being freed in libxfs_alloc_file_space error paths;
more or less copy the error handling that exists
in kernelspace to resolve this.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
libxfs/util.c

index 1b0554067f23b1973c6e7ddef74d082d3096b6de..03befb732e93f056e647ccea94ae98e9d917013f 100644 (file)
@@ -582,8 +582,17 @@ libxfs_alloc_file_space(
                resblks = (uint)XFS_DIOSTRAT_SPACE_RES(mp, datablocks);
                error = xfs_trans_reserve(tp, &M_RES(mp)->tr_write,
                                          resblks, 0);
-               if (error)
+               /*
+                * Check for running out of space
+                */
+               if (error) {
+                       /*
+                        * Free the transaction structure.
+                        */
+                       ASSERT(error == ENOSPC);
+                       xfs_trans_cancel(tp, 0);
                        break;
+               }
                xfs_trans_ijoin(tp, ip, 0);
                xfs_trans_ihold(tp, ip);
 
@@ -593,12 +602,12 @@ libxfs_alloc_file_space(
                                &reccount, &free_list);
 
                if (error)
-                       break;
+                       goto error0;
 
                /* complete the transaction */
                error = xfs_bmap_finish(&tp, &free_list, &committed);
                if (error)
-                       break;
+                       goto error0;
 
                error = xfs_trans_commit(tp, 0);
                if (error)
@@ -612,6 +621,11 @@ libxfs_alloc_file_space(
                allocatesize_fsb -= allocated_fsb;
        }
        return error;
+
+error0:        /* Cancel bmap, cancel trans */
+       xfs_bmap_cancel(&free_list);
+       xfs_trans_cancel(tp, 0);
+       return error;
 }
 
 unsigned int