[PATCH 07/13] jffs2: Fix memory leak in jffs2_scan_eraseblock() error path
Sebastian Huber
sebastian.huber at embedded-brains.de
Fri Jun 10 08:20:59 UTC 2022
From: Wenwen Wang <wenwen at cs.uga.edu>
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 <wenwen at cs.uga.edu>
Signed-off-by: Richard Weinberger <richard at nod.at>
---
cpukit/libfs/src/jffs2/src/scan.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/cpukit/libfs/src/jffs2/src/scan.c b/cpukit/libfs/src/jffs2/src/scan.c
index 177a0cdd3f..d5441448b0 100644
--- a/cpukit/libfs/src/jffs2/src/scan.c
+++ b/cpukit/libfs/src/jffs2/src/scan.c
@@ -530,8 +530,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;
+ }
}
}
--
2.35.3
More information about the devel
mailing list