Skip to content

Commit

Permalink
mtd: fix memory leaks in phram_setup
Browse files Browse the repository at this point in the history
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@gmail.com>
Signed-off-by: David Woodhouse <dwmw2@infradead.org>
  • Loading branch information
Jesper Juhl authored and David Woodhouse committed May 13, 2006
1 parent e0c7d76 commit 4f678a5
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions drivers/mtd/devices/phram.c
Original file line number Diff line number Diff line change
Expand Up @@ -266,12 +266,16 @@ static int phram_setup(const char *val, struct kernel_param *kp)
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);

Expand Down

0 comments on commit 4f678a5

Please sign in to comment.