public inbox for linux-xfs@vger.kernel.org
 help / color / mirror / Atom feed
From: Eric Sandeen <sandeen@redhat.com>
To: Eric Sandeen <sandeen@redhat.com>
Cc: xfs-oss <xfs@oss.sgi.com>
Subject: [PATCH 1/3] xfs_repair: Fix fragmented multiblock dir2 handling in blkmap_getn()
Date: Mon, 21 May 2012 17:10:06 -0500	[thread overview]
Message-ID: <4FBABD3E.2050700@redhat.com> (raw)
In-Reply-To: <4FBABCAB.20300@redhat.com>

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>
---

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 " bytes)\n"),
 						nb * sizeof(bmap_ext_t));

_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

  reply	other threads:[~2012-05-21 22:10 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-21 22:07 [PATCH 0/3] xfs_repair fixes for fragmented multiblock v2 dirs Eric Sandeen
2012-05-21 22:10 ` Eric Sandeen [this message]
2012-05-31 20:55   ` [PATCH 1/3] xfs_repair: Fix fragmented multiblock dir2 handling in blkmap_getn() Ben Myers
2012-05-21 22:10 ` [PATCH 2/3] xfs_repair: Document & robustify blkmap_next_off() Eric Sandeen
2012-05-31 21:27   ` Ben Myers
2012-05-21 22:11 ` [PATCH 3/3] xfs_repair: handle fragmented multiblock dir2 in process_leaf_node_dir2() Eric Sandeen
2012-06-01 20:25   ` Ben Myers
2012-05-22  1:26 ` [PATCH 0/3] xfs_repair fixes for fragmented multiblock v2 dirs Eric Sandeen
2012-05-22 13:41 ` [PATCH 2/3 RESEND] " Eric Sandeen
2012-05-22 13:42 ` [PATCH 3/3 RESEND] xfs_repair: handle fragmented multiblock dir2 in process_leaf_node_dir2() Eric Sandeen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4FBABD3E.2050700@redhat.com \
    --to=sandeen@redhat.com \
    --cc=xfs@oss.sgi.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox