linux-scsi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Douglas Gilbert <dgilbert@interlog.com>
To: SCSI development list <linux-scsi@vger.kernel.org>
Cc: James Bottomley <james.bottomley@hansenpartnership.com>,
	Vegard Nossum <vegard.nossum@oracle.com>,
	vaughan <vaughan.cao@oracle.com>
Subject: [PATCH] sg: fix memory leaks
Date: Thu, 26 Sep 2013 13:54:10 -0400	[thread overview]
Message-ID: <524474C2.6010600@interlog.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 420 bytes --]

This patch plugs two memory leaks in the sg driver. The
first was reported by Vegard Nossum and the second was
found by checking for the same pattern.

ChangeLog:
    - close two heap memory leaks. The first is an error
      path; the second is associated with getting debug
      information from procfs and sysfs.

The patch is generated from lk 3.12.0-rc2 .


Signed-off-by: Douglas Gilbert <dgilbert@interlog.com>


[-- Attachment #2: sg_leaks312rc2.patch --]
[-- Type: text/x-patch, Size: 647 bytes --]

diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
index 5cbc4bb..aa86276 100644
--- a/drivers/scsi/sg.c
+++ b/drivers/scsi/sg.c
@@ -2060,6 +2060,7 @@ sg_add_sfp(Sg_device * sdp, int dev)
 	spin_lock_irqsave(&sdp->sfd_lock, iflags);
 	if (sdp->detached) {
 		spin_unlock_irqrestore(&sdp->sfd_lock, iflags);
+		kfree(sfp);
 		return ERR_PTR(-ENODEV);
 	}
 	list_add_tail(&sfp->sfd_siblings, &sdp->sfds);
@@ -2433,8 +2434,10 @@ static void * dev_seq_start(struct seq_file *s, loff_t *pos)
 
 	it->index = *pos;
 	it->max = sg_last_dev();
-	if (it->index >= it->max)
+	if (it->index >= it->max) {
+		kfree(it);
 		return NULL;
+	}
 	return it;
 }
 


                 reply	other threads:[~2013-09-26 17:54 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=524474C2.6010600@interlog.com \
    --to=dgilbert@interlog.com \
    --cc=james.bottomley@hansenpartnership.com \
    --cc=linux-scsi@vger.kernel.org \
    --cc=vaughan.cao@oracle.com \
    --cc=vegard.nossum@oracle.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;
as well as URLs for NNTP newsgroup(s).