Skip to contentSkip to conversation

UBI: fastmap: fix a mem leak on error path

PATCH In review Richard Genoud 2 participants 2 messages Sep 27, 2013

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 UBI: fastmap: fix a mem leak on error path

If the scan_pool() function fails, the "free" list is not freed. This leads to destroy_ai(ai) complaining with:
"kmem_cache_destroy ubi_ainf_peb_slab: Slab cache still has objects"

---
 drivers/mtd/ubi/fastmap.c |    4 ++++
 1 file changed, 4 insertions(+)
drivers/mtd/ubi/fastmap.c +4 -0
index 05067f5..22eb527 100644
@@ -841,6 +841,10 @@ static int ubi_attach_fastmap(struct ubi_device *ubi,
 fail_bad:
 	ret = UBI_BAD_FASTMAP;
 fail:
+	list_for_each_entry_safe(tmp_aeb, _tmp_aeb, &free, u.list) {
+		kmem_cache_free(ai->aeb_slab_cache, tmp_aeb);
+		list_del(&tmp_aeb->u.list);
+	}
 	return ret;
 }
 
Signature · 1 line
1.7.10.4
#1 lore raw

Am 27.09.2013 17:37, schrieb Richard Genoud:

Quoted 3 lines

If the scan_pool() function fails, the "free" list is not freed. This leads to destroy_ai(ai) complaining with:
"kmem_cache_destroy ubi_ainf_peb_slab: Slab cache still has objects"

Hmm, I *think* we need to take care about used and eba_orphans too. Tomorrow I'll have time to investigate...

Thanks,
//richard

Quoted 21 lines
---
 drivers/mtd/ubi/fastmap.c |    4 ++++
 1 file changed, 4 insertions(+)
drivers/mtd/ubi/fastmap.c +4 -0
index 05067f5..22eb527 100644
@@ -841,6 +841,10 @@ static int ubi_attach_fastmap(struct ubi_device *ubi,
 fail_bad:
 	ret = UBI_BAD_FASTMAP;
 fail:
+	list_for_each_entry_safe(tmp_aeb, _tmp_aeb, &free, u.list) {
+		kmem_cache_free(ai->aeb_slab_cache, tmp_aeb);
+		list_del(&tmp_aeb->u.list);
+	}
 	return ret;
 }