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
This commit is contained in:
Jaehyun Cho 2020-08-04 15:11:35 +09:00
parent 5af8301bad
commit cc0328d9e5
1 changed files with 8 additions and 7 deletions

View File

@ -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");