edje_embryo: fix memory leak in ALLOC_COPY_DESC
authorJaehyun Cho <jae_hyun.cho@samsung.com>
Tue, 4 Aug 2020 06:11:35 +0000 (15:11 +0900)
committerJongmin Lee <jm105.lee@samsung.com>
Tue, 4 Aug 2020 21:15:57 +0000 (06:15 +0900)
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

index b4ffbfc..bb3828a 100644 (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");