[Top] [All Lists]

[PATCH 1/3] xfs_repair: Fix fragmented multiblock dir2 handling in blkma

To: Eric Sandeen <sandeen@xxxxxxxxxx>
Subject: [PATCH 1/3] xfs_repair: Fix fragmented multiblock dir2 handling in blkmap_getn()
From: Eric Sandeen <sandeen@xxxxxxxxxx>
Date: Mon, 21 May 2012 17:10:06 -0500
Cc: xfs-oss <xfs@xxxxxxxxxxx>
In-reply-to: <4FBABCAB.20300@xxxxxxxxxx>
References: <4FBABCAB.20300@xxxxxxxxxx>
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:12.0) Gecko/20120428 Thunderbird/12.0.1
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

Signed-off-by: Eric Sandeen <sandeen@xxxxxxxxxx>

diff --git a/repair/bmap.c b/repair/bmap.c
index 2f1c307..c43ca7f 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 " 
                                                nb * sizeof(bmap_ext_t));

<Prev in Thread] Current Thread [Next in Thread>