From cecd19803eb2d60fbb69162acb19a063ca7ed4f4 Mon Sep 17 00:00:00 2001 From: Cedric Bail Date: Tue, 16 Jul 2013 20:02:47 +0900 Subject: [PATCH] eo: let's handle memory allocation gracefully. --- src/lib/eo/eo_base_class.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/lib/eo/eo_base_class.c b/src/lib/eo/eo_base_class.c index eb83d2c410..ab318df684 100644 --- a/src/lib/eo/eo_base_class.c +++ b/src/lib/eo/eo_base_class.c @@ -73,6 +73,7 @@ _data_set(Eo *obj, void *class_data, va_list *list) eo_do(obj, eo_base_data_del(key)); node = malloc(sizeof(Eo_Generic_Data_Node)); + if (!node) return; node->key = eina_stringshare_add(key); node->data = (void *) data; node->free_func = free_func; @@ -157,13 +158,16 @@ _wref_add(Eo *obj, void *class_data, va_list *list) { Private_Data *pd = (Private_Data *) class_data; size_t count; + Eo ***tmp; EO_PARAMETER_GET(Eo **, wref, list); count = _wref_count(pd); count += 1; /* New wref. */ - pd->wrefs= realloc(pd->wrefs, sizeof(*pd->wrefs) * (count + 1)); + tmp = realloc(pd->wrefs, sizeof(*pd->wrefs) * (count + 1)); + if (!tmp) return ; + pd->wrefs = tmp; pd->wrefs[count - 1] = wref; pd->wrefs[count] = NULL; @@ -216,8 +220,11 @@ _wref_del(Eo *obj, void *class_data, va_list *list) if (count > 1) { + Eo ***tmp; // No count--; because of the NULL that is not included in the count. */ - pd->wrefs = realloc(pd->wrefs, sizeof(*pd->wrefs) * count); + tmp = realloc(pd->wrefs, sizeof(*pd->wrefs) * count); + if (!tmp) return ; + pd->wrefs = tmp; pd->wrefs[count - 1] = NULL; } else @@ -370,6 +377,7 @@ _ev_cb_priority_add(Eo *obj, void *class_data, va_list *list) EO_PARAMETER_GET(const void *, data, list); cb = calloc(1, sizeof(*cb)); + if (!cb) return ; cb->items.item.desc = desc; cb->items.item.func = func; cb->func_data = (void *) data; @@ -421,6 +429,7 @@ _ev_cb_array_priority_add(Eo *obj, void *class_data, va_list *list) EO_PARAMETER_GET(const void *, data, list); cb = calloc(1, sizeof(*cb)); + if (!cb) return ; cb->func_data = (void *) data; cb->priority = priority; cb->items.item_array = array; @@ -647,7 +656,9 @@ _eo_dbg_info_copy(const Eina_Value_Type *type EINA_UNUSED, const void *_src, voi { const Eo_Dbg_Info **src = (const Eo_Dbg_Info **) _src; Eo_Dbg_Info **dst = _dst; + *dst = calloc(1, sizeof(Eo_Dbg_Info)); + if (!*dst) return EINA_FALSE; (*dst)->name = eina_stringshare_ref((*src)->name); eina_value_copy(&((*src)->value), &((*dst)->value)); return EINA_TRUE;