[PATCH] rsxx: core: fix memory leak

From: Andi Shyti
Date: Mon Aug 19 2013 - 06:21:14 EST


if 'copy_from_user' fails, the 'rsxx_cram_write()' function
returns without freeing the allocated buffer 'buf'.

Free 'buf' before returning.

This issue has been reported by scan.coverity.com

Signed-off-by: Andi Shyti <andi@xxxxxxxxxxx>
---
drivers/block/rsxx/core.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/block/rsxx/core.c b/drivers/block/rsxx/core.c
index 6e85e21..1ddb284 100644
--- a/drivers/block/rsxx/core.c
+++ b/drivers/block/rsxx/core.c
@@ -223,8 +223,10 @@ static ssize_t rsxx_cram_write(struct file *fp, const char __user *ubuf,
return -ENOMEM;

st = copy_from_user(buf, ubuf, cnt);
- if (st)
+ if (st) {
+ kfree(buf);
return st;
+ }

info->f_pos = (u32)*ppos + info->offset;

--
1.8.4.rc2

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/