mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] rsxx: core: fix memory leak
@ 2013-08-19 10:20 Andi Shyti
  2013-08-19 16:36 ` [PATCH v2 0/1] fix meamleak on rsxx/core.c Andi Shyti
  0 siblings, 1 reply; 3+ messages in thread
From: Andi Shyti @ 2013-08-19 10:20 UTC (permalink / raw)
  To: josh.h.morris, pjk1939; +Cc: linux-kernel, andi

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@etezian.org>
---
 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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH v2 0/1] fix meamleak on rsxx/core.c
  2013-08-19 10:20 [PATCH] rsxx: core: fix memory leak Andi Shyti
@ 2013-08-19 16:36 ` Andi Shyti
  2013-08-19 16:36   ` [PATCH v2 1/1] rsxx: core: fix memory leak Andi Shyti
  0 siblings, 1 reply; 3+ messages in thread
From: Andi Shyti @ 2013-08-19 16:36 UTC (permalink / raw)
  To: josh.h.morris, pjk1939; +Cc: linux-kernel, andi

Hi,

this version is a bit better since it fixes two memleak situations.

Andi

Andi Shyti (1):
  rsxx: core: fix memory leak

 drivers/block/rsxx/core.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

-- 
1.8.4.rc2


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH v2 1/1] rsxx: core: fix memory leak
  2013-08-19 16:36 ` [PATCH v2 0/1] fix meamleak on rsxx/core.c Andi Shyti
@ 2013-08-19 16:36   ` Andi Shyti
  0 siblings, 0 replies; 3+ messages in thread
From: Andi Shyti @ 2013-08-19 16:36 UTC (permalink / raw)
  To: josh.h.morris, pjk1939; +Cc: linux-kernel, andi

Free 'buf' before returning.

the 'rsxx_cram_write()' function returns twice without freeing
the allocated buffer 'buf' causing a possible memory leak.

This issue has been reported by scan.coverity.com

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

diff --git a/drivers/block/rsxx/core.c b/drivers/block/rsxx/core.c
index 6e85e21..fa3740b 100644
--- a/drivers/block/rsxx/core.c
+++ b/drivers/block/rsxx/core.c
@@ -224,19 +224,20 @@ static ssize_t rsxx_cram_write(struct file *fp, const char __user *ubuf,
 
 	st = copy_from_user(buf, ubuf, cnt);
 	if (st)
-		return st;
+		goto exit;
 
 	info->f_pos = (u32)*ppos + info->offset;
 
 	st = rsxx_creg_write(card, CREG_ADD_CRAM + info->f_pos, cnt, buf, 1);
 	if (st)
-		return st;
+		goto exit;
 
 	info->offset += cnt;
 
+exit:
 	kfree(buf);
 
-	return cnt;
+	return st ? st : cnt;
 }
 
 static int rsxx_cram_open(struct inode *inode, struct file *file)
-- 
1.8.4.rc2


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2013-08-19 16:37 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-08-19 10:20 [PATCH] rsxx: core: fix memory leak Andi Shyti
2013-08-19 16:36 ` [PATCH v2 0/1] fix meamleak on rsxx/core.c Andi Shyti
2013-08-19 16:36   ` [PATCH v2 1/1] rsxx: core: fix memory leak Andi Shyti

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®