evas_smart: Add a check for zero size before malloc
authorVaibhav Gupta <g.vaibhav1@samsung.com>
Fri, 12 Jun 2015 08:47:13 +0000 (09:47 +0100)
committerTom Hacohen <tom@stosb.com>
Fri, 12 Jun 2015 08:47:13 +0000 (09:47 +0100)
Summary:
Size may be zero while allocating interfaces private data,
when NULL is passed in EVAS_SMART_SUBCLASS_IFACE_NEW for ifaces argument.

If size is 0, then malloc() returns either NULL, or a unique pointer
value that can later be successfully passed to free(). It is implementation
dependent. This case would be likely to occur in case of smart classes with
no interfaces.

@fix

Signed-off-by: Vaibhav Gupta <g.vaibhav1@samsung.com>
Reviewers: raster, Hermet, tasn, cedric

Subscribers: SanghyeonLee, sachin.dev, singh.amitesh, cedric

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

src/lib/evas/canvas/evas_object_smart.c

index 252e71a..27fca2b 100644 (file)
@@ -496,6 +496,8 @@ _evas_smart_class_ifaces_private_data_alloc(Evas_Object *eo_obj,
           }
      }
 
+   if (!s->interfaces.size && !total_priv_sz) return;
+
    obj = eo_data_scope_get(eo_obj, MY_CLASS);
    obj->interface_privates = malloc(s->interfaces.size * sizeof(void *) + total_priv_sz);
    if (!obj->interface_privates)