diff mbox

[6/7] UBI: Fix memory leak in ubi_attach_fastmap() error path

Message ID 1380376516-30144-7-git-send-email-richard@nod.at
State Accepted
Commit fe24c6e5f51ec5ea42d432f67618a084047a23ed
Headers show

Commit Message

Richard Weinberger Sept. 28, 2013, 1:55 p.m. UTC
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>
---
 drivers/mtd/ubi/fastmap.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

Comments

Richard Genoud Sept. 30, 2013, 8:13 a.m. UTC | #1
2013/9/28 Richard Weinberger <richard@nod.at>:
> 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>
> ---
>  drivers/mtd/ubi/fastmap.c | 13 +++++++++++++
>  1 file changed, 13 insertions(+)
>
> diff --git a/drivers/mtd/ubi/fastmap.c b/drivers/mtd/ubi/fastmap.c
> index 05067f5..4cfc8da 100644
> --- a/drivers/mtd/ubi/fastmap.c
> +++ b/drivers/mtd/ubi/fastmap.c
> @@ -841,6 +841,19 @@ 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, &used, u.list) {
> +               kmem_cache_free(ai->aeb_slab_cache, tmp_aeb);
> +               list_del(&tmp_aeb->u.list);
> +       }
> +       list_for_each_entry_safe(tmp_aeb, _tmp_aeb, &eba_orphans, u.list) {
> +               kmem_cache_free(ai->aeb_slab_cache, tmp_aeb);
> +               list_del(&tmp_aeb->u.list);
> +       }
> +       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;
>  }
>
> --
> 1.8.3.1
>

Works like a charm !
Tested-by: Richard Genoud <richard.genoud@gmail.com>


Thanks !
diff mbox

Patch

diff --git a/drivers/mtd/ubi/fastmap.c b/drivers/mtd/ubi/fastmap.c
index 05067f5..4cfc8da 100644
--- a/drivers/mtd/ubi/fastmap.c
+++ b/drivers/mtd/ubi/fastmap.c
@@ -841,6 +841,19 @@  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, &used, u.list) {
+		kmem_cache_free(ai->aeb_slab_cache, tmp_aeb);
+		list_del(&tmp_aeb->u.list);
+	}
+	list_for_each_entry_safe(tmp_aeb, _tmp_aeb, &eba_orphans, u.list) {
+		kmem_cache_free(ai->aeb_slab_cache, tmp_aeb);
+		list_del(&tmp_aeb->u.list);
+	}
+	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;
 }