summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCedric BAIL <cedric.bail@free.fr>2019-11-07 16:17:06 -0800
committerMarcel Hollerbach <mail@marcel-hollerbach.de>2019-11-13 21:16:11 +0100
commit6cec0df499f16f452ceeba270384cb476a5f3ce8 (patch)
tree021fb22393761124bcc393d3fadee11cba594ad2
parentf71a109e70b7a952cbac204d78f4142350083892 (diff)
elementary: fix initialization order and memory leak when setting model on Efl.Ui.CollectionView.
This patch use volatile model to make sure that a model is properly cleaned once it is not used anymore. Reviewed-by: Marcel Hollerbach <mail@marcel-hollerbach.de> Differential Revision: https://phab.enlightenment.org/D10625
-rw-r--r--src/lib/elementary/efl_ui_collection_view.c53
1 files changed, 26 insertions, 27 deletions
diff --git a/src/lib/elementary/efl_ui_collection_view.c b/src/lib/elementary/efl_ui_collection_view.c
index 8d8b215..e3d4c96 100644
--- a/src/lib/elementary/efl_ui_collection_view.c
+++ b/src/lib/elementary/efl_ui_collection_view.c
@@ -1874,7 +1874,9 @@ static void
1874_efl_ui_collection_view_model_changed(void *data, const Efl_Event *event) 1874_efl_ui_collection_view_model_changed(void *data, const Efl_Event *event)
1875{ 1875{
1876 Efl_Model_Changed_Event *ev = event->info; 1876 Efl_Model_Changed_Event *ev = event->info;
1877#ifdef VIEWPORT_ENABLE
1877 Eina_List *requests = NULL; 1878 Eina_List *requests = NULL;
1879#endif
1878 MY_DATA_GET(data, pd); 1880 MY_DATA_GET(data, pd);
1879 Eina_Iterator *it; 1881 Eina_Iterator *it;
1880 const char *property; 1882 const char *property;
@@ -1883,22 +1885,21 @@ _efl_ui_collection_view_model_changed(void *data, const Efl_Event *event)
1883 Efl_Model *mselect = NULL; 1885 Efl_Model *mselect = NULL;
1884 Eina_Bool selection = EINA_FALSE, sizing = EINA_FALSE; 1886 Eina_Bool selection = EINA_FALSE, sizing = EINA_FALSE;
1885 1887
1886 // Cleanup all object, pending request and refetch everything 1888 // Cleanup all object, pending request to prepare refetching everything
1887 _all_cleanup(data, pd); 1889 _all_cleanup(data, pd);
1888
1889 if (pd->model) efl_event_callback_array_del(pd->model, model_cbs(), data); 1890 if (pd->model) efl_event_callback_array_del(pd->model, model_cbs(), data);
1890 efl_replace(&pd->model, NULL); 1891 if (pd->multi_selectable_async_model)
1892 {
1893 efl_event_callback_forwarder_del(pd->multi_selectable_async_model,
1894 EFL_UI_SELECTABLE_EVENT_SELECTION_CHANGED,
1895 data);
1896 efl_composite_detach(data, pd->multi_selectable_async_model);
1897 }
1891 1898
1892 if (!ev->current) 1899 if (!ev->current)
1893 { 1900 {
1894 if (pd->multi_selectable_async_model) 1901 efl_replace(&pd->model, NULL);
1895 { 1902 efl_replace(&pd->multi_selectable_async_model, NULL);
1896 efl_event_callback_forwarder_del(pd->multi_selectable_async_model,
1897 EFL_UI_SELECTABLE_EVENT_SELECTION_CHANGED,
1898 data);
1899 efl_composite_detach(data, pd->multi_selectable_async_model);
1900 efl_replace(&pd->multi_selectable_async_model, NULL);
1901 }
1902 return ; 1903 return ;
1903 } 1904 }
1904 1905
@@ -1937,15 +1938,9 @@ _efl_ui_collection_view_model_changed(void *data, const Efl_Event *event)
1937 // Build and connect the selection model properly 1938 // Build and connect the selection model properly
1938 if (!mselect) 1939 if (!mselect)
1939 { 1940 {
1940 mselect = model = efl_add(EFL_UI_SELECT_MODEL_CLASS, data, 1941 mselect = model = efl_add_ref(EFL_UI_SELECT_MODEL_CLASS, data,
1941 efl_ui_view_model_set(efl_added, model)); 1942 efl_ui_view_model_set(efl_added, model),
1942 } 1943 efl_loop_model_volatile_make(efl_added));
1943 if (pd->multi_selectable_async_model)
1944 {
1945 efl_event_callback_forwarder_del(pd->multi_selectable_async_model,
1946 EFL_UI_SELECTABLE_EVENT_SELECTION_CHANGED,
1947 data);
1948 efl_composite_detach(data, pd->multi_selectable_async_model);
1949 } 1944 }
1950 efl_replace(&pd->multi_selectable_async_model, mselect); 1945 efl_replace(&pd->multi_selectable_async_model, mselect);
1951 efl_composite_attach(data, pd->multi_selectable_async_model); 1946 efl_composite_attach(data, pd->multi_selectable_async_model);
@@ -1953,8 +1948,15 @@ _efl_ui_collection_view_model_changed(void *data, const Efl_Event *event)
1953 EFL_UI_SELECTABLE_EVENT_SELECTION_CHANGED, 1948 EFL_UI_SELECTABLE_EVENT_SELECTION_CHANGED,
1954 data); 1949 data);
1955 1950
1956 if (!sizing) model = efl_add(EFL_UI_HOMOGENEOUS_MODEL_CLASS, data, 1951 if (!sizing) model = efl_add_ref(EFL_UI_HOMOGENEOUS_MODEL_CLASS, data,
1957 efl_ui_view_model_set(efl_added, model)); 1952 efl_ui_view_model_set(efl_added, model),
1953 efl_loop_model_volatile_make(efl_added));
1954
1955 efl_replace(&pd->model, model);
1956 efl_event_callback_array_add(pd->model, model_cbs(), data);
1957
1958 if (mselect) efl_unref(mselect);
1959 if (!sizing) efl_unref(model);
1958 1960
1959 count = efl_model_children_count_get(model); 1961 count = efl_model_children_count_get(model);
1960 1962
@@ -1976,13 +1978,9 @@ _efl_ui_collection_view_model_changed(void *data, const Efl_Event *event)
1976 1978
1977 requests = eina_list_append(requests, request); 1979 requests = eina_list_append(requests, request);
1978 } 1980 }
1979#endif
1980 requests = _batch_request_flush(requests, data, pd); 1981 requests = _batch_request_flush(requests, data, pd);
1982#endif
1981 1983
1982 pd->model = model;
1983 efl_event_callback_array_add(pd->model, model_cbs(), data);
1984
1985 efl_ui_position_manager_entity_item_size_changed(pd->manager, 0, count - 1);
1986 switch(efl_ui_position_manager_entity_version(pd->manager, 1)) 1984 switch(efl_ui_position_manager_entity_version(pd->manager, 1))
1987 { 1985 {
1988 case 1: 1986 case 1:
@@ -1992,6 +1990,7 @@ _efl_ui_collection_view_model_changed(void *data, const Efl_Event *event)
1992 count); 1990 count);
1993 break; 1991 break;
1994 } 1992 }
1993 efl_ui_position_manager_entity_item_size_changed(pd->manager, 0, count - 1);
1995} 1994}
1996 1995
1997static void 1996static void