Skip to contentSkip to conversation

leak in mtd/devices/phram.c

PATCH Eric Sesterhenn / Snakebyte 3 participants 3 messages May 20, 2007 – May 22, 2007

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

hi,

coverity spotted this leak in mtd/devices/phram.c (bug id #1512), when register_device() fails, we dont kfree() name and leak it, attached patch should fix this.

drivers/mtd/devices/phram.c renamed from drivers/mtd/devices/phram.c.orig +3 -1
@@ -276,7 +276,9 @@ static int phram_setup(const char *val, 
 		parse_err("illegal device length\n");
 	}
 
-	register_device(name, start, len);
+	ret = register_device(name, start, len);
+	if (ret)
+		kfree(name);
 
 	return 0;
 }
maintainer Acked-by
#1 lore raw
Quoted 6 lines · Eric Sesterhenn / Snakebyte

coverity spotted this leak in mtd/devices/phram.c (bug id #1512), when register_device() fails, we dont kfree() name and leak it, attached patch should fix this.

Quoted 4 lines

drivers/mtd/devices/phram.c static int phram_setup(const char *val, · line 284

Quoted 10 lines
drivers/mtd/devices/phram.c renamed from drivers/mtd/devices/phram.c.orig +3 -1
@@ -276,7 +276,9 @@ static int phram_setup(const char *val, 
 		parse_err("illegal device length\n");
 	}
 
-	register_device(name, start, len);
+	ret = register_device(name, start, len);
+	if (ret)
+		kfree(name);
 
 	return 0;
 }

Jörn

Signature · 3 lines
I can say that I spend most of my time fixing bugs even if I have lots
of new features to implement in mind, but I give bugs more priority.
-- Andrea Arcangeli, 2000
#2 lore raw
In reply to Eric Sesterhenn / Snakebyte
Quoted 8 lines · Eric Sesterhenn / Snakebyte <snakebyte <at> gmx.de> writes:

hi,

coverity spotted this leak in mtd/devices/phram.c (bug id #1512), when register_device() fails, we dont kfree() name and leak it, attached patch should fix this.

Signed-off-by Eric Sesterhenn <snakebyte <at> gmx.de>

It's good that the drivers are now getting audited for kmalloc/kfree (see other recent kfree patch).
Keep it up !! How about a driver memory leak reg-test ?!

Regards,
MikeW