mtd: fix memory leak in block2mtd_setup()
Linux-MTD Mailing List
linux-mtd at lists.infradead.org
Sat May 13 20:59:02 EDT 2006
commit a6550e57f9d074511cf420bdb802ab5e56edc3bb
tree 56010126c6a1660b6fbd97765c73f8808214f98c
parent 552d9205186428a1e2a49ed577bcbba9f777af37
author Jesper Juhl <jesper.juhl at gmail.com> Sun, 14 May 2006 01:42:25 +0200
committer David Woodhouse <dwmw2 at infradead.org> Sun, 14 May 2006 01:21:31 +0100
mtd: fix memory leak in block2mtd_setup()
There's a mem leak in drivers/mtd/devices/block2mtd.c::block2mtd_setup()
We can leak 'name' allocated with kmalloc in 'parse_name' if leave via
the 'parse_err' macro since it contains a return but doesn't do any
freeing.
Spotted by coverity checker as bug 615.
Signed-off-by: Jesper Juhl <jesper.juhl at gmail.com>
Signed-off-by: David Woodhouse <dwmw2 at infradead.org>
drivers/mtd/devices/block2mtd.c | 9 ++++++---
1 files changed, 6 insertions(+), 3 deletions(-)
diff --git a/drivers/mtd/devices/block2mtd.c b/drivers/mtd/devices/block2mtd.c
index f54e4bf..4560692 100644
--- a/drivers/mtd/devices/block2mtd.c
+++ b/drivers/mtd/devices/block2mtd.c
@@ -429,7 +429,8 @@ #define parse_err(fmt, args...) do { \
static int block2mtd_setup(const char *val, struct kernel_param *kp)
{
- char buf[80+12], *str=buf; /* 80 for device, 12 for erase size */
+ char buf[80+12]; /* 80 for device, 12 for erase size */
+ char *str = buf;
char *token[2];
char *name;
size_t erase_size = PAGE_SIZE;
@@ -441,7 +442,7 @@ static int block2mtd_setup(const char *v
strcpy(str, val);
kill_final_newline(str);
- for (i=0; i<2; i++)
+ for (i = 0; i < 2; i++)
token[i] = strsep(&str, ",");
if (str)
@@ -460,8 +461,10 @@ static int block2mtd_setup(const char *v
if (token[1]) {
ret = parse_num(&erase_size, token[1]);
- if (ret)
+ if (ret) {
+ kfree(name);
parse_err("illegal erase size");
+ }
}
add_device(name, erase_size);
More information about the linux-mtd-cvs
mailing list