mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andi Shyti <andi@etezian.org>
To: josh.h.morris@us.ibm.com, pjk1939@linux.vnet.ibm.com
Cc: linux-kernel@vger.kernel.org, andi@etezian.org
Subject: [PATCH v2 1/1] rsxx: core: fix memory leak
Date: Mon, 19 Aug 2013 18:36:36 +0200	[thread overview]
Message-ID: <1376930196-21785-2-git-send-email-andi@etezian.org> (raw)
In-Reply-To: <1376930196-21785-1-git-send-email-andi@etezian.org>

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


      reply	other threads:[~2013-08-19 16:37 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-08-19 10:20 [PATCH] " Andi Shyti
2013-08-19 16:36 ` [PATCH v2 0/1] fix meamleak on rsxx/core.c Andi Shyti
2013-08-19 16:36   ` Andi Shyti [this message]

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=1376930196-21785-2-git-send-email-andi@etezian.org \
    --to=andi@etezian.org \
    --cc=josh.h.morris@us.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pjk1939@linux.vnet.ibm.com \
    /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®