Skip to contentSkip to conversation

sg: fix memory leaks

PATCH New Douglas Gilbert 1 participant 1 message Sep 26, 2013

Subsystems (2)
lore
Share & tools
lore

Douglas Gilbert

author maintainer
#0 lore raw

PATCH 1/1 sg: fix memory leaks

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 .

drivers/scsi/sg.c +4 -1
index 5cbc4bb..aa86276 100644
@@ -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;
 }