From: David Woodhouse Date: Sun, 21 May 2006 00:28:05 +0000 (+0100) Subject: [JFFS2] Fix memory leak in scan code; improve comments. X-Git-Tag: v2.6.18-rc1~1105^2~74^2~9 X-Git-Url: http://pilppa.com/gitweb/?a=commitdiff_plain;h=3560160aa26ebced1944aaa2e7e436d2a1b1bf70;p=linux-2.6-omap-h63xx.git [JFFS2] Fix memory leak in scan code; improve comments. If we had to allocate extra space for the summary node, we weren't correctly freeing it when jffs2_sum_scan_sumnode() returned nonzero -- which is both the success and the failure case. Only when it returned zero, which means fall through to the full scan, were we correctly freeing the buffer. Document the meaning of those return codes while we're at it. Signed-off-by: David Woodhouse --- diff --git a/fs/jffs2/scan.c b/fs/jffs2/scan.c index 06637050749..192b0bd2118 100644 --- a/fs/jffs2/scan.c +++ b/fs/jffs2/scan.c @@ -516,10 +516,15 @@ static int jffs2_scan_eraseblock (struct jffs2_sb_info *c, struct jffs2_eraseblo if (sumptr) { err = jffs2_sum_scan_sumnode(c, jeb, sumptr, sumlen, &pseudo_random); - if (err) - return err; + if (buf_size && sumlen > buf_size) kfree(sumptr); + /* If it returns with a real error, bail. + If it returns positive, that's a block classification + (i.e. BLK_STATE_xxx) so return that too. + If it returns zero, fall through to full scan. */ + if (err) + return err; } }