From 98c2a75bda3fdea34a8ae9c3751b7893e3d5f830 Mon Sep 17 00:00:00 2001 From: Jaehyun Cho Date: Thu, 19 Sep 2019 09:49:39 +0000 Subject: [PATCH] elementary: unref objects when memory allocation fails in factory The objects referenced are unreferenced when memory allocation fails in elementary factory. Differential Revision: https://phab.enlightenment.org/D9968 --- src/lib/elementary/efl_ui_caching_factory.c | 21 ++++++++++----------- src/lib/elementary/efl_ui_widget_factory.c | 19 +++++++++---------- 2 files changed, 19 insertions(+), 21 deletions(-) diff --git a/src/lib/elementary/efl_ui_caching_factory.c b/src/lib/elementary/efl_ui_caching_factory.c index 245830f161..09ec342845 100644 --- a/src/lib/elementary/efl_ui_caching_factory.c +++ b/src/lib/elementary/efl_ui_caching_factory.c @@ -180,6 +180,7 @@ _efl_ui_caching_factory_efl_ui_factory_create(Eo *obj, Efl_Ui_Caching_Factory_Data *pd, Eina_Iterator *models, Efl_Gfx_Entity *parent) { + Efl_Ui_Caching_Factory_Request *r; Efl_Ui_Caching_Factory_Group_Request *gr; Efl_Gfx_Entity *w = NULL; Efl_Model *model; @@ -187,7 +188,6 @@ _efl_ui_caching_factory_efl_ui_factory_create(Eo *obj, if (pd->cache && pd->style && !pd->klass) { - Efl_Ui_Caching_Factory_Request *r; Eina_Future **all; int count = 0; @@ -199,11 +199,7 @@ _efl_ui_caching_factory_efl_ui_factory_create(Eo *obj, r->factory = efl_ref(obj); all = calloc(1, sizeof (Eina_Future *)); - if (!all) - { - free(r); - return efl_loop_future_rejected(obj, ENOMEM); - } + if (!all) goto alloc_array_error; EINA_ITERATOR_FOREACH(models, model) { @@ -213,11 +209,7 @@ _efl_ui_caching_factory_efl_ui_factory_create(Eo *obj, .data = r); all = realloc(all, (count + 1) * sizeof (Eina_Future *)); - if (!all) - { - free(r); - return efl_loop_future_rejected(obj, ENOMEM); - } + if (!all) goto alloc_array_error; } eina_iterator_free(models); @@ -274,6 +266,13 @@ _efl_ui_caching_factory_efl_ui_factory_create(Eo *obj, .success_type = EINA_VALUE_TYPE_ARRAY, .data = gr, .free = _efl_ui_caching_factory_group_cleanup); + +alloc_array_error: + efl_unref(r->parent); + efl_unref(r->factory); + free(r); + eina_iterator_free(models); + return efl_loop_future_rejected(obj, ENOMEM); } static void diff --git a/src/lib/elementary/efl_ui_widget_factory.c b/src/lib/elementary/efl_ui_widget_factory.c index 4b1523dd01..ffb02753d9 100644 --- a/src/lib/elementary/efl_ui_widget_factory.c +++ b/src/lib/elementary/efl_ui_widget_factory.c @@ -201,11 +201,7 @@ _efl_ui_widget_factory_efl_ui_factory_create(Eo *obj, Efl_Ui_Widget_Factory_Data r->factory = efl_ref(obj); f = calloc(count + 1, sizeof (Eina_Future *)); - if (!f) - { - free(r); - return efl_loop_future_rejected(obj, ENOMEM); - } + if (!f) goto alloc_array_error; EINA_ITERATOR_FOREACH(models, model) { @@ -214,11 +210,7 @@ _efl_ui_widget_factory_efl_ui_factory_create(Eo *obj, Efl_Ui_Widget_Factory_Data .free = _efl_ui_widget_factory_single_cleanup); f = realloc(f, (count + 1) * sizeof (Eina_Future *)); - if (!f) - { - free(r); - return efl_loop_future_rejected(obj, ENOMEM); - } + if (!f) goto alloc_array_error; } eina_iterator_free(models); @@ -227,6 +219,13 @@ _efl_ui_widget_factory_efl_ui_factory_create(Eo *obj, Efl_Ui_Widget_Factory_Data return efl_future_then(obj, eina_future_all_array(f), .data = r, .free = _efl_ui_widget_factory_create_cleanup); + +alloc_array_error: + efl_unref(r->parent); + efl_unref(r->factory); + free(r); + eina_iterator_free(models); + return efl_loop_future_rejected(obj, ENOMEM); } static void