mtd: fix memory leak in block2mtd_setup()
Subsystems (2)
PATCH 1/1 mtd: fix memory leak in block2mtd_setup()
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 <[email protected]>
---
drivers/mtd/devices/block2mtd.c | 9 ++++++--- 1 files changed, 6 insertions(+), 3 deletions(-)
drivers/mtd/devices/block2mtd.c +6 -3
@@ -418,7 +418,8 @@ static inline void kill_final_newline(chstatic 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 *vstrcpy (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 *vif (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);
David Woodhouse
AppliedQuoted 7 lines · Jesper Juhl
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.
Applied; thanks.
Signature · 1 line
dwmw2