Skip to contentSkip to conversation

Fix device_attribute memory leak in device_del

PATCH New Catalin Marinas 1 participant 1 message Nov 18, 2006 Driver core

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix device_attribute memory leak in device_del

dev->devt_attr is allocated in device_add() but it is never freed in device_del() in the drivers/base/core.c file (reported by kmemleak).

---

I sent this patch before for 2.6.18 but it probably got lost. Anyway, I found the bug again while testing kmemleak.

 drivers/base/core.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
drivers/base/core.c +3 -1
index 68ad11a..002fde4 100644
@@ -591,8 +591,10 @@ void device_del(struct device * dev)
 
 	if (parent)
 		klist_del(&dev->knode_parent);
-	if (dev->devt_attr)
+	if (dev->devt_attr) {
 		device_remove_file(dev, dev->devt_attr);
+		kfree(dev->devt_attr);
+	}
 	if (dev->class) {
 		sysfs_remove_link(&dev->kobj, "subsystem");
 		sysfs_remove_link(&dev->class->subsys.kset.kobj, dev->bus_id);