elementary: make sure fileselector button model has a parent and self destruct properly.
authorCedric BAIL <cedric@osg.samsung.com>
Thu, 24 May 2018 03:19:31 +0000 (20:19 -0700)
committerWonki Kim <wonki_.kim@samsung.com>
Fri, 1 Jun 2018 03:52:13 +0000 (12:52 +0900)
src/lib/elementary/elc_fileselector_button.c

index ec59905..19ba340 100644 (file)
@@ -189,6 +189,27 @@ _button_clicked(void *data, const Efl_Event *event EINA_UNUSED)
    _activate(data);
 }
 
+static void _noref_death(void *data EINA_UNUSED, const Efl_Event *event);
+static void _invalidated(void *data EINA_UNUSED, const Efl_Event *event);
+
+EFL_CALLBACKS_ARRAY_DEFINE(noref_death,
+                           { EFL_EVENT_NOREF, _noref_death },
+                           { EFL_EVENT_INVALIDATE, _invalidated });
+
+static void
+_noref_death(void *data EINA_UNUSED, const Efl_Event *event)
+{
+   efl_event_callback_array_del(event->object, noref_death(), NULL);
+   efl_del(event->object);
+}
+
+static void
+_invalidated(void *data EINA_UNUSED, const Efl_Event *event)
+{
+   // This means our parent is dying, EFL_EVENT_NOREF can be called after invalidated
+   efl_event_callback_array_del(event->object, noref_death(), NULL);
+}
+
 EOLIAN static void
 _elm_fileselector_button_efl_canvas_group_group_add(Eo *obj, Elm_Fileselector_Button_Data *priv)
 {
@@ -202,7 +223,9 @@ _elm_fileselector_button_efl_canvas_group_group_add(Eo *obj, Elm_Fileselector_Bu
    if (path) priv->fsd.path = eina_stringshare_add(path);
    else priv->fsd.path = eina_stringshare_add("/");
 
-   priv->fsd.model = efl_add_ref(EIO_MODEL_CLASS, NULL, eio_model_path_set(efl_added, priv->fsd.path));
+   priv->fsd.model = efl_add_ref(EIO_MODEL_CLASS, obj,
+                                 eio_model_path_set(efl_added, priv->fsd.path),
+                                 efl_event_callback_array_add(efl_added, noref_death(), NULL));
 
    priv->fsd.expandable = _elm_config->fileselector_expand_enable;
    priv->inwin_mode = _elm_config->inwin_dialogs_enable;