]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs_repair: Fix fragmented multiblock dir2 handling in blkmap_getn()
authorEric Sandeen <sandeen@redhat.com>
Tue, 5 Jun 2012 18:24:55 +0000 (13:24 -0500)
committerEric Sandeen <sandeen@sandeen.net>
Tue, 5 Jun 2012 18:24:55 +0000 (13:24 -0500)
blkmap_getn() contains a loop which populates an array of extents
with mapping information for a dir2 "block," which may consist
of multiple filesystem blocks.

As written, the loop re-allocates the array for each new extent,
leaking the previously allocated memory and worse, losing the
previously filled-in extent information.

Fix this by only allocating the array once, for the maximum
possible number of extents - the number of fs blocks in the dir
block.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Reviewed-by: Ben Myers <bpm@sgi.com>
repair/bmap.c

index 2f1c307c9ac4795fe4afcc26fbcc715c4aa14e0b..c43ca7f70d08d5a27bf16db28b83501fac43abbe 100644 (file)
@@ -168,7 +168,8 @@ blkmap_getn(
                /*
                 * rare case - multiple extents for a single dir block
                 */
-               bmp = malloc(nb * sizeof(bmap_ext_t));
+               if (!bmp)
+                       bmp = malloc(nb * sizeof(bmap_ext_t));
                if (!bmp)
                        do_error(_("blkmap_getn malloc failed (%" PRIu64 " bytes)\n"),
                                                nb * sizeof(bmap_ext_t));