mtd: fix memory leaks in phram_setup
Linux-MTD Mailing List
linux-mtd at lists.infradead.org
Sat May 13 19:59:02 EDT 2006
commit 4f678a58d335291ce9213c049bbe16e6d24487ed
tree 136a3406bf5b0e80b3d45cd4d3c6ca40bb9961fd
parent e0c7d7675331140e5186d2d1a0efce1d3877d379
author Jesper Juhl <jesper.juhl at gmail.com> Sun, 14 May 2006 01:07:18 +0200
committer David Woodhouse <dwmw2 at infradead.org> Sun, 14 May 2006 00:13:30 +0100
mtd: fix memory leaks in phram_setup
There are two code paths in drivers/mtd/devices/phram.c::phram_setup() that
will leak memory.
Memory is allocated to the variable 'name' with kmalloc() by the
parse_name() function, but if we leave by way of the parse_err() macro,
then that memory is never kfree()'d, nor is it ever used with
register_device() so it won't be freed later either - leak.
Found by the Coverity checker as #593 - simple fix below.
Signed-off-by: Jesper Juhl <jesper.juhl at gmail.com>
Signed-off-by: David Woodhouse <dwmw2 at infradead.org>
drivers/mtd/devices/phram.c | 8 ++++++--
1 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/drivers/mtd/devices/phram.c b/drivers/mtd/devices/phram.c
index 41af969..68d39cc 100644
--- a/drivers/mtd/devices/phram.c
+++ b/drivers/mtd/devices/phram.c
@@ -266,12 +266,16 @@ static int phram_setup(const char *val,
return 0;
ret = parse_num32(&start, token[1]);
- if (ret)
+ if (ret) {
+ kfree(name);
parse_err("illegal start address\n");
+ }
ret = parse_num32(&len, token[2]);
- if (ret)
+ if (ret) {
+ kfree(name);
parse_err("illegal device length\n");
+ }
register_device(name, start, len);
More information about the linux-mtd-cvs
mailing list