edje_edit: add NULL check for eina_mempool_malloc in _edje_edit_state_alloc()
authorJEONGHYUN YUN <jh0506.yun@samsung.com>
Thu, 6 Apr 2017 21:23:19 +0000 (14:23 -0700)
committerCedric BAIL <cedric@osg.samsung.com>
Thu, 6 Apr 2017 22:20:49 +0000 (15:20 -0700)
Summary: Pointer eina_mempool_malloc return value may have NULL value when
module aren't properly installed. This reduce the chance of a crash and increase
the likelyness of properly handling the failure.

Reviewers: jpeg, jypark

Subscribers: cedric, jpeg

Differential Revision: https://phab.enlightenment.org/D4763

Signed-off-by: Cedric BAIL <cedric@osg.samsung.com>
src/lib/edje/edje_edit.c

index d2616fc..ac387b3 100644 (file)
@@ -6307,31 +6307,36 @@ _edje_edit_state_alloc(int type, Edje *ed)
      {
       case EDJE_PART_TYPE_RECTANGLE:
         pd = eina_mempool_malloc(ce->mp->mp.RECTANGLE, sizeof (Edje_Part_Description_Common));
+        if (!pd) return NULL;
         ce->count.RECTANGLE++;
         break;
 
       case EDJE_PART_TYPE_SPACER:
         pd = eina_mempool_malloc(ce->mp->mp.SPACER, sizeof (Edje_Part_Description_Common));
+        if (!pd) return NULL;
         ce->count.SPACER++;
         break;
 
       case EDJE_PART_TYPE_SWALLOW:
         pd = eina_mempool_malloc(ce->mp->mp.SWALLOW, sizeof (Edje_Part_Description_Common));
+        if (!pd) return NULL;
         ce->count.SWALLOW++;
         break;
 
       case EDJE_PART_TYPE_GROUP:
         pd = eina_mempool_malloc(ce->mp->mp.GROUP, sizeof (Edje_Part_Description_Common));
+        if (!pd) return NULL;
         ce->count.GROUP++;
         break;
 
 #define EDIT_ALLOC_POOL(Short, Type, Name)                            \
 case EDJE_PART_TYPE_##Short:                                          \
 {                                                                     \
-   Edje_Part_Description_##Type * Name;                               \
+   Edje_Part_Description_##Type *Name = NULL;                         \
                                                                       \
    Name = eina_mempool_malloc(ce->mp->mp.Short,                       \
                               sizeof (Edje_Part_Description_##Type)); \
+   if (!Name) return NULL;                                            \
    memset(Name, 0, sizeof(Edje_Part_Description_##Type));             \
    pd = &Name->common;                                                \
    ce->count.Short++;                                                 \