From 989c343d1643cb562ecca1bfcffa36074fbc6f08 Mon Sep 17 00:00:00 2001 From: Ryuan Choi Date: Thu, 27 Jun 2013 15:21:37 +0900 Subject: [PATCH] fileselector : Fix Segfault in elementary file_selector_example when closed https://phab.enlightenment.org/T133 list_itc and grid_itc are static variables, but they were managed by file_selector instance. For example, they are allocated two times and first allocated classes are dangling when two file selector are created. This patch moves their init/deinit logic to constructor/destructor of file selector class. --- legacy/elementary/ChangeLog | 5 ++ legacy/elementary/NEWS | 1 + legacy/elementary/src/lib/elc_fileselector.c | 52 +++++++++++--------- 3 files changed, 35 insertions(+), 23 deletions(-) diff --git a/legacy/elementary/ChangeLog b/legacy/elementary/ChangeLog index 29358d8bae..50e4839429 100644 --- a/legacy/elementary/ChangeLog +++ b/legacy/elementary/ChangeLog @@ -1463,3 +1463,8 @@ * Gesture Layer: add APIs to add/del multiple callbacks for a same gesture/type/state. + +2013-06-25 Ryuan Choi (ryuan) + + * Fix Segfault in elementary file_selector_example when closed. + https://phab.enlightenment.org/T133 diff --git a/legacy/elementary/NEWS b/legacy/elementary/NEWS index e0b81e0a61..2210dbc820 100644 --- a/legacy/elementary/NEWS +++ b/legacy/elementary/NEWS @@ -252,6 +252,7 @@ Fixes: * Fix elm_scroller_page_show bug. It have to save the wanted values to show the wanted page. * Block mouse events when the ctxpopup on dismiss. * Fix crash of elm_notify when timeout is zero. + * Fix Segfault in elementary file_selector_example when closed Removals: diff --git a/legacy/elementary/src/lib/elc_fileselector.c b/legacy/elementary/src/lib/elc_fileselector.c index 3b7880e060..a8755fdd31 100644 --- a/legacy/elementary/src/lib/elc_fileselector.c +++ b/legacy/elementary/src/lib/elc_fileselector.c @@ -815,7 +815,6 @@ static void _elm_fileselector_smart_add(Eo *obj, void *_pd, va_list *list EINA_UNUSED) { Evas_Object *ic, *bt, *li, *en, *grid, *pb; - unsigned int i; int s; Elm_Fileselector_Smart_Data *priv = _pd; @@ -866,19 +865,6 @@ _elm_fileselector_smart_add(Eo *obj, void *_pd, va_list *list EINA_UNUSED) elm_widget_sub_object_add(obj, pb); priv->spinner = pb; - for (i = 0; i < ELM_FILE_LAST; ++i) - { - list_itc[i] = elm_genlist_item_class_new(); - grid_itc[i] = elm_gengrid_item_class_new(); - - list_itc[i]->item_style = "default"; - list_itc[i]->func.text_get = grid_itc[i]->func.text_get = - _itc_text_get; - list_itc[i]->func.state_get = grid_itc[i]->func.state_get = - _itc_state_get; - list_itc[i]->func.del = grid_itc[i]->func.del = _itc_del; - } - list_itc[ELM_DIRECTORY]->func.content_get = grid_itc[ELM_DIRECTORY]->func.content_get = _itc_icon_folder_get; list_itc[ELM_FILE_IMAGE]->func.content_get = @@ -942,17 +928,9 @@ _elm_fileselector_smart_add(Eo *obj, void *_pd, va_list *list EINA_UNUSED) static void _elm_fileselector_smart_del(Eo *obj EINA_UNUSED, void *_pd, va_list *list EINA_UNUSED) { - int i; - Elm_Fileselector_Smart_Data *sd = _pd; Elm_Fileselector_Filter *filter; - for (i = 0; i < ELM_FILE_LAST; ++i) - { - elm_genlist_item_class_free(list_itc[i]); - elm_gengrid_item_class_free(grid_itc[i]); - } - #ifdef HAVE_EIO if (sd->current) eio_file_cancel(sd->current); #endif @@ -1444,6 +1422,8 @@ _elm_fileselector_smart_focus_direction_manager_is(Eo *obj EINA_UNUSED, void *_p static void _class_constructor(Eo_Class *klass) { + unsigned int i; + const Eo_Op_Func_Description func_desc[] = { EO_OP_FUNC(EO_BASE_ID(EO_BASE_SUB_ID_CONSTRUCTOR), _constructor), @@ -1477,7 +1457,33 @@ _class_constructor(Eo_Class *klass) eo_class_funcs_set(klass, func_desc); evas_smart_legacy_type_register(MY_CLASS_NAME, klass); + + for (i = 0; i < ELM_FILE_LAST; ++i) + { + list_itc[i] = elm_genlist_item_class_new(); + grid_itc[i] = elm_gengrid_item_class_new(); + + list_itc[i]->item_style = "default"; + list_itc[i]->func.text_get = grid_itc[i]->func.text_get = + _itc_text_get; + list_itc[i]->func.state_get = grid_itc[i]->func.state_get = + _itc_state_get; + list_itc[i]->func.del = grid_itc[i]->func.del = _itc_del; + } } + +static void +_class_destructor(Eo_Class *klass EINA_UNUSED) +{ + unsigned int i; + + for (i = 0; i < ELM_FILE_LAST; ++i) + { + elm_genlist_item_class_free(list_itc[i]); + elm_gengrid_item_class_free(grid_itc[i]); + } +} + static const Eo_Op_Description op_desc[] = { EO_OP_DESCRIPTION(ELM_OBJ_FILESELECTOR_SUB_ID_IS_SAVE_SET, "Enable/disable the file name entry box where the user can type in a name for a file, in a given file selector widget."), EO_OP_DESCRIPTION(ELM_OBJ_FILESELECTOR_SUB_ID_IS_SAVE_GET, "Get whether the given file selector is in 'saving dialog' mode."), @@ -1505,6 +1511,6 @@ static const Eo_Class_Description class_desc = { NULL, sizeof(Elm_Fileselector_Smart_Data), _class_constructor, - NULL + _class_destructor }; EO_DEFINE_CLASS(elm_obj_fileselector_class_get, &class_desc, ELM_OBJ_LAYOUT_CLASS, NULL);