jaehyun pushed a commit to branch master.

http://git.enlightenment.org/core/efl.git/commit/?id=cc0328d9e50573ec45715238258c167622702fc1

commit cc0328d9e50573ec45715238258c167622702fc1
Author: Jaehyun Cho <jae_hyun....@samsung.com>
Date:   Tue Aug 4 15:11:35 2020 +0900

    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 b4ffbfc32d..bb3828ab3d 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");

-- 


Reply via email to