mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] mtd: fix memory leaks in phram_setup
@ 2006-05-13 23:07 Jesper Juhl
  2006-05-13 23:18 ` David Woodhouse
  0 siblings, 1 reply; 9+ messages in thread
From: Jesper Juhl @ 2006-05-13 23:07 UTC (permalink / raw)
  To: linux-kernel
  Cc: Jochen Schäuble, Jörn Engel, Thomas Gleixner, Jesper Juhl


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>
---


 drivers/mtd/devices/phram.c |    8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)


--- linux-2.6.17-rc4-git2-orig/drivers/mtd/devices/phram.c	2006-03-20 06:53:29.000000000 +0100
+++ linux-2.6.17-rc4-git2/drivers/mtd/devices/phram.c	2006-05-14 01:05:27.000000000 +0200
@@ -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);
 





^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2006-05-14 20:07 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-05-13 23:07 [PATCH] mtd: fix memory leaks in phram_setup Jesper Juhl
2006-05-13 23:18 ` David Woodhouse
2006-05-13 23:34   ` Jesper Juhl
2006-05-13 23:40     ` David Woodhouse
2006-05-14  6:37       ` Jörn Engel
2006-05-14 11:03         ` David Woodhouse
2006-05-14 13:21           ` Jörn Engel
2006-05-14 16:37             ` Ingo Oeser
2006-05-14 20:07               ` Jörn Engel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®