From: Eric Sandeen Date: Tue, 5 Jun 2012 18:24:55 +0000 (-0500) Subject: xfs_repair: Fix fragmented multiblock dir2 handling in blkmap_getn() X-Git-Tag: v3.1.9-rc1~16 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b220548bf2e51f4a573b19b4a8b4b15856bd4a06;p=thirdparty%2Fxfsprogs-dev.git xfs_repair: Fix fragmented multiblock dir2 handling in blkmap_getn() 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 Reviewed-by: Ben Myers --- diff --git a/repair/bmap.c b/repair/bmap.c index 2f1c307c9..c43ca7f70 100644 --- a/repair/bmap.c +++ b/repair/bmap.c @@ -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));