From e4c2b671eab2c60be0e0cbef373b8a9a02a4c9f6 Mon Sep 17 00:00:00 2001 From: Jaehyun Cho Date: Tue, 4 Aug 2020 15:11:35 +0900 Subject: [PATCH] edje_embryo: fix memory leak in ALLOC_COPY_DESC Summary: If memory allocation fails in ALLOC_COPY_DESC, then the allocated memory is not free. To fix this memory leak, memory allocation of Edje_Real_Part_State is done prior to ALLOC_COPY_DESC. Reviewers: Hermet Reviewed By: Hermet Subscribers: cedric, #reviewers, #committers Tags: #efl Differential Revision: https://phab.enlightenment.org/D12082 --- src/lib/edje/edje_embryo.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/lib/edje/edje_embryo.c b/src/lib/edje/edje_embryo.c index b4ffbfc..bb3828a 100644 --- a/src/lib/edje/edje_embryo.c +++ b/src/lib/edje/edje_embryo.c @@ -2089,6 +2089,11 @@ _edje_embryo_fn_custom_state(Embryo_Program *ep, Embryo_Cell *params) if (!(parent = _edje_part_description_find(ed, rp, name, val, EINA_TRUE))) return 0; + rp->custom = eina_mempool_malloc(_edje_real_part_state_mp, sizeof (Edje_Real_Part_State)); + if (!rp->custom) return 0; + + memset(rp->custom, 0, sizeof (Edje_Real_Part_State)); + /* now create the custom state */ switch (rp->part->type) { @@ -2123,17 +2128,13 @@ case EDJE_PART_TYPE_##Short: \ ALLOC_COPY_DESC(VECTOR, Vector, d, vg); } - if (!d) return 0; - - rp->custom = eina_mempool_malloc(_edje_real_part_state_mp, sizeof (Edje_Real_Part_State)); - if (!rp->custom) + if (!d) { - free(d); + eina_mempool_free(_edje_real_part_state_mp, rp->custom); + rp->custom = NULL; return 0; } - memset(rp->custom, 0, sizeof (Edje_Real_Part_State)); - *d = *parent; d->state.name = (char *)eina_stringshare_add("custom"); -- 2.7.4