From 7c2a1932c733866e6a7e8ce89e5e7f5c75449599 Mon Sep 17 00:00:00 2001 From: Cedric BAIL Date: Tue, 13 Mar 2018 12:40:02 -0400 Subject: [PATCH] efl_ui_clock: do not locally store clock module api there is no corresponding code to unset this global pointer when the module is unloaded, so this will crash if elm_shutdown is ever called Signed-off-by: Mike Blumenkrantz --- src/lib/elementary/efl_ui_clock.c | 61 ++++++++++++++++++++----------- 1 file changed, 39 insertions(+), 22 deletions(-) diff --git a/src/lib/elementary/efl_ui_clock.c b/src/lib/elementary/efl_ui_clock.c index 274346ded4..dec9b2dfaa 100644 --- a/src/lib/elementary/efl_ui_clock.c +++ b/src/lib/elementary/efl_ui_clock.c @@ -65,7 +65,6 @@ static Format_Map mapping[EFL_UI_CLOCK_TYPE_COUNT] = { static const char *multifield_formats = "cxXrRTDF"; static const char *ignore_separators = "()"; static const char *ignore_extensions = "E0_-O^#"; -static Clock_Mod_Api *dt_mod = NULL; static const char SIG_CHANGED[] = "changed"; static const Evas_Smart_Cb_Description _smart_callbacks[] = { @@ -77,27 +76,34 @@ static const Evas_Smart_Cb_Description _smart_callbacks[] = { {NULL, NULL} }; +static Elm_Module * +_dt_mod_find(void) +{ + static int tried_fallback = 0; + Elm_Module *mod = _elm_module_find_as("clock/api"); + + if (mod) return mod; + if (!tried_fallback && + (!_elm_config->modules || !strstr(_elm_config->modules, "clock/api"))) + { + // See also _config_update(): we hardcode here the default module + ERR("Elementary config does not contain the required module " + "name for the clock widget! Verify your installation."); + _elm_module_add("clock_input_ctxpopup", "clock/api"); + mod = _elm_module_find_as("clock/api"); + tried_fallback = EINA_TRUE; + } + return mod; +} + static Clock_Mod_Api * _dt_mod_init() { - static int tried_fallback = 0; - Elm_Module *mod = NULL; - - if (!(mod = _elm_module_find_as("clock/api"))) - { - if (!tried_fallback && - (!_elm_config->modules || !strstr(_elm_config->modules, "clock/api"))) - { - // See also _config_update(): we hardcode here the default module - ERR("Elementary config does not contain the required module " - "name for the clock widget! Verify your installation."); - _elm_module_add("clock_input_ctxpopup", "clock/api"); - mod = _elm_module_find_as("clock/api"); - tried_fallback = EINA_TRUE; - } - if (!mod) return NULL; - } + Elm_Module *mod; + mod = _dt_mod_find(); + if (!mod) return NULL; + if (mod->api) return mod->api; mod->api = malloc(sizeof(Clock_Mod_Api)); if (!mod->api) return NULL; @@ -120,9 +126,11 @@ _field_list_display(Evas_Object *obj) { Clock_Field *field; unsigned int idx = 0; + Clock_Mod_Api *dt_mod; EFL_UI_CLOCK_DATA_GET(obj, sd); + dt_mod = _dt_mod_init(); if (!dt_mod || !dt_mod->field_value_display) return; for (idx = 0; idx < EFL_UI_CLOCK_TYPE_COUNT; idx++) @@ -457,6 +465,7 @@ _efl_ui_clock_efl_ui_focus_object_on_focus_update(Eo *obj, Efl_Ui_Clock_Data *sd if (!efl_ui_focus_object_focus_get(obj)) { + Clock_Mod_Api *dt_mod = _dt_mod_init(); if ((dt_mod) && (dt_mod->obj_hide)) dt_mod->obj_hide(sd->mod_data); } @@ -507,12 +516,14 @@ _efl_ui_clock_efl_ui_widget_theme_apply(Eo *obj, Efl_Ui_Clock_Data *sd) Clock_Field *field; char buf[BUFFER_SIZE]; unsigned int idx; + Clock_Mod_Api *dt_mod; ELM_WIDGET_DATA_GET_OR_RETURN(obj, wd, EINA_FALSE); int_ret = efl_ui_widget_theme_apply(efl_super(obj, MY_CLASS)); if (!int_ret) return EFL_UI_THEME_APPLY_FAILED; + dt_mod = _dt_mod_init(); if ((!dt_mod) || (!dt_mod->field_value_display)) return EINA_TRUE; for (idx = 0; idx < EFL_UI_CLOCK_TYPE_COUNT; idx++) @@ -804,6 +815,7 @@ _ticker(void *data) if (sd->curr_time.tm_sec > 0) { + Clock_Mod_Api *dt_mod = _dt_mod_init(); field = sd->field_list + EFL_UI_CLOCK_TYPE_SECOND; if (field->fmt_exist && field->visible && dt_mod && dt_mod->field_value_display) @@ -823,6 +835,7 @@ EOLIAN static void _efl_ui_clock_efl_canvas_group_group_add(Eo *obj, Efl_Ui_Clock_Data *priv) { Clock_Field *field; + Clock_Mod_Api *dt_mod; int idx; ELM_WIDGET_DATA_GET_OR_RETURN(obj, wd); @@ -838,7 +851,7 @@ _efl_ui_clock_efl_canvas_group_group_add(Eo *obj, Efl_Ui_Clock_Data *priv) CRI("Failed to set layout!"); // module - initialise module for clock - if (!dt_mod) dt_mod = _dt_mod_init(); + dt_mod = _dt_mod_init(); if (dt_mod) { if (dt_mod->obj_hook) @@ -898,6 +911,7 @@ _efl_ui_clock_efl_canvas_group_group_del(Eo *obj, Efl_Ui_Clock_Data *sd) { Clock_Field *tmp; unsigned int idx; + Clock_Mod_Api *dt_mod; ecore_timer_del(sd->ticker); for (idx = 0; idx < EFL_UI_CLOCK_TYPE_COUNT; idx++) @@ -907,6 +921,7 @@ _efl_ui_clock_efl_canvas_group_group_del(Eo *obj, Efl_Ui_Clock_Data *sd) eina_stringshare_del(tmp->separator); } + dt_mod = _dt_mod_init(); if ((dt_mod) && (dt_mod->obj_unhook)) dt_mod->obj_unhook(sd->mod_data); // module - unhook @@ -1008,9 +1023,11 @@ _efl_ui_clock_field_visible_set(Eo *obj, Efl_Ui_Clock_Data *sd, Efl_Ui_Clock_Typ elm_layout_sizing_eval(obj); if (!visible) return; - if (!dt_mod || !dt_mod->field_value_display) return; - - dt_mod->field_value_display(sd->mod_data, field->item_obj); + { + Clock_Mod_Api *dt_mod = _dt_mod_init(); + if (!dt_mod || !dt_mod->field_value_display) return; + dt_mod->field_value_display(sd->mod_data, field->item_obj); + } } EOLIAN static void