]> err.no Git - linux-2.6/commitdiff
mtd: fix memory leak in block2mtd_setup()
authorJesper Juhl <jesper.juhl@gmail.com>
Sat, 13 May 2006 23:42:25 +0000 (01:42 +0200)
committerDavid Woodhouse <dwmw2@infradead.org>
Sun, 14 May 2006 00:21:31 +0000 (01:21 +0100)
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>
Signed-off-by: David Woodhouse <dwmw2@infradead.org>
drivers/mtd/devices/block2mtd.c

index f54e4bf9b968f153400312a74689f7028650b5d4..45606921364b0c008c8b288f34b078c6de5432b6 100644 (file)
@@ -429,7 +429,8 @@ static inline void kill_final_newline(char *str)
 
 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;
@@ -441,7 +442,7 @@ static int block2mtd_setup(const char *val, struct kernel_param *kp)
        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)
@@ -460,8 +461,10 @@ static int block2mtd_setup(const char *val, struct kernel_param *kp)
 
        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);