Skip to content

Commit

Permalink
jffs2: Fix memory leak in jffs2_scan_eraseblock() error path
Browse files Browse the repository at this point in the history
In jffs2_scan_eraseblock(), 'sumptr' is allocated through kmalloc() if
'sumlen' is larger than 'buf_size'. However, it is not deallocated in the
following execution if jffs2_fill_scan_buf() fails, leading to a memory
leak bug. To fix this issue, free 'sumptr' before returning the error.

Signed-off-by: Wenwen Wang <[email protected]>
Signed-off-by: Richard Weinberger <[email protected]>
  • Loading branch information
wenwenwang1 authored and richardweinberger committed Sep 15, 2019
1 parent 61b875e commit 6a379f6
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion fs/jffs2/scan.c
Original file line number Diff line number Diff line change
Expand Up @@ -527,8 +527,11 @@ static int jffs2_scan_eraseblock (struct jffs2_sb_info *c, struct jffs2_eraseblo
err = jffs2_fill_scan_buf(c, sumptr,
jeb->offset + c->sector_size - sumlen,
sumlen - buf_len);
if (err)
if (err) {
if (sumlen > buf_size)
kfree(sumptr);
return err;
}
}
}

Expand Down

0 comments on commit 6a379f6

Please sign in to comment.