mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jesper Juhl <jesper.juhl@gmail.com>
To: linux-kernel@vger.kernel.org
Cc: "Simon Evans" <spse@secret.org.uk>,
	"Jörn Engel" <joern@wohnheim.fh-wedel.de>,
	"David Woodhouse" <dwmw2@infradead.org>,
	"Jesper Juhl" <jesper.juhl@gmail.com>
Subject: [PATCH] mtd: fix memory leak in block2mtd_setup()
Date: Sun, 14 May 2006 01:42:25 +0200	[thread overview]
Message-ID: <200605140142.25486.jesper.juhl@gmail.com> (raw)

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@gmail.com>
---


 drivers/mtd/devices/block2mtd.c |    9 ++++++---
 1 files changed, 6 insertions(+), 3 deletions(-)


--- linux-2.6.17-rc4-git2-orig/drivers/mtd/devices/block2mtd.c	2006-05-13 21:28:27.000000000 +0200
+++ linux-2.6.17-rc4-git2/drivers/mtd/devices/block2mtd.c	2006-05-14 01:33:36.000000000 +0200
@@ -418,7 +418,8 @@ static inline void kill_final_newline(ch
 
 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;
@@ -430,7 +431,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)
@@ -449,8 +450,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);





             reply	other threads:[~2006-05-13 23:41 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-05-13 23:42 Jesper Juhl [this message]
2006-05-14  0:43 ` David Woodhouse

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200605140142.25486.jesper.juhl@gmail.com \
    --to=jesper.juhl@gmail.com \
    --cc=dwmw2@infradead.org \
    --cc=joern@wohnheim.fh-wedel.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=spse@secret.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®