Skip to content

Commit fe24c6e

Browse files
richardweinbergerdedekind
authored andcommitted
UBI: Fix memory leak in ubi_attach_fastmap() error path
On error we have to free all three temporary lists. Reported-by: Richard Genoud <richard.genoud@gmail.com> Signed-off-by: Richard Weinberger <richard@nod.at> Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
1 parent 55b80c4 commit fe24c6e

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

‎drivers/mtd/ubi/fastmap.c‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -841,6 +841,19 @@ static int ubi_attach_fastmap(struct ubi_device *ubi,
841841
fail_bad:
842842
ret = UBI_BAD_FASTMAP;
843843
fail:
844+
list_for_each_entry_safe(tmp_aeb, _tmp_aeb, &used, u.list) {
845+
kmem_cache_free(ai->aeb_slab_cache, tmp_aeb);
846+
list_del(&tmp_aeb->u.list);
847+
}
848+
list_for_each_entry_safe(tmp_aeb, _tmp_aeb, &eba_orphans, u.list) {
849+
kmem_cache_free(ai->aeb_slab_cache, tmp_aeb);
850+
list_del(&tmp_aeb->u.list);
851+
}
852+
list_for_each_entry_safe(tmp_aeb, _tmp_aeb, &free, u.list) {
853+
kmem_cache_free(ai->aeb_slab_cache, tmp_aeb);
854+
list_del(&tmp_aeb->u.list);
855+
}
856+
844857
return ret;
845858
}
846859

0 commit comments

Comments
 (0)