This is an automated email from the git hooks/post-receive script.

git pushed a commit to branch master
in repository efl.

View the commit online.

commit 371beb5b61731f49e05484c513f3380b9d8d96d3
Author: Cedric BAIL <[email protected]>
AuthorDate: Sun Nov 15 12:50:39 2026 -0600

    elementary: collection_view unrefs only the select model it made
    
    Efl.Ui.Collection_View finds a select model already in the chain of the
    model it is given and reuses it, and adds a reference only when it
    creates one itself. It dropped one unconditionally at the end of
    model_changed, so a model the application gave took a reference the
    function never owned, and the application's own was gone when the view
    was deleted.
    
    Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
 src/lib/elementary/efl_ui_collection_view.c        |  7 ++++-
 src/tests/elementary/efl_ui_test_collection_view.c | 32 ++++++++++++++++++++++
 2 files changed, 38 insertions(+), 1 deletion(-)

diff --git a/src/lib/elementary/efl_ui_collection_view.c b/src/lib/elementary/efl_ui_collection_view.c
index d85b0135fe..5eccb5b5ac 100644
--- a/src/lib/elementary/efl_ui_collection_view.c
+++ b/src/lib/elementary/efl_ui_collection_view.c
@@ -2428,6 +2428,10 @@ _efl_ui_collection_view_model_changed(void *data, const Efl_Event *event)
    unsigned int count;
    Efl_Model *mselect = NULL;
    Eina_Bool selection = EINA_FALSE, sizing = EINA_FALSE;
+   /* Whether the select model below is one this function made. A model that
+      already provides selection is found in the chain and reused, and
+      unreffing that one drops a reference this function never took. */
+   Eina_Bool mselect_made_here = EINA_FALSE;
 
    // Cleanup all object, pending request to prepare refetching everything
    _all_cleanup(data, pd);
@@ -2488,6 +2492,7 @@ _efl_ui_collection_view_model_changed(void *data, const Efl_Event *event)
         mselect = model = efl_add_ref(EFL_UI_SELECT_MODEL_CLASS, data,
                                       efl_ui_view_model_set(efl_added, model),
                                       efl_loop_model_volatile_make(efl_added));
+        mselect_made_here = EINA_TRUE;
      }
    efl_replace(&pd->multi_selectable_async_model, mselect);
    efl_composite_attach(data, pd->multi_selectable_async_model);
@@ -2509,7 +2514,7 @@ _efl_ui_collection_view_model_changed(void *data, const Efl_Event *event)
    pd->last_count = efl_model_children_count_get(model);
    efl_event_callback_array_add(pd->model, model_cbs(), data);
 
-   if (mselect) efl_unref(mselect);
+   if (mselect_made_here) efl_unref(mselect);
    if (!sizing) efl_unref(model);
 
    count = efl_model_children_count_get(model);
diff --git a/src/tests/elementary/efl_ui_test_collection_view.c b/src/tests/elementary/efl_ui_test_collection_view.c
index c75cd3a6e3..a71b37b0ce 100644
--- a/src/tests/elementary/efl_ui_test_collection_view.c
+++ b/src/tests/elementary/efl_ui_test_collection_view.c
@@ -2530,6 +2530,37 @@ EFL_START_TEST(efl_ui_collection_view_lets_go_of_its_factory)
 }
 EFL_END_TEST
 
+// A select model the application gives the view is reused by it, and the
+// view lets go only of the references it took: the application's own is left.
+EFL_START_TEST(efl_ui_collection_view_keeps_a_given_select_model)
+{
+   Efl_Ui_Win *win;
+   Efl_Model *model, *selection;
+   Efl_Ui_Factory *fl;
+   Efl_Ui_Collection_View *cv;
+   int refs;
+
+   win = win_add(NULL, "win", EFL_UI_WIN_TYPE_BASIC);
+   model = _make_model(win);
+   selection = efl_add_ref(EFL_UI_SELECT_MODEL_CLASS, win,
+                           efl_ui_view_model_set(efl_added, model));
+   refs = efl_ref_count(selection);
+
+   fl = efl_add(EFL_UI_LAYOUT_FACTORY_CLASS, win,
+                efl_ui_widget_factory_item_class_set(efl_added, EFL_UI_LIST_DEFAULT_ITEM_CLASS));
+   cv = efl_add(EFL_UI_LIST_VIEW_CLASS, win,
+                efl_ui_collection_view_factory_set(efl_added, fl),
+                efl_ui_view_model_set(efl_added, selection));
+   efl_content_set(win, cv);
+   get_me_to_those_events(cv);
+   ck_assert_int_gt(efl_ref_count(selection), refs);
+
+   efl_del(cv);
+   ck_assert_int_eq(efl_ref_count(selection), refs);
+   efl_unref(selection);
+}
+EFL_END_TEST
+
 void efl_ui_test_collection_view(TCase *tc)
 {
    tcase_add_test(tc, test_efl_ui_collection_view_basic);
@@ -2569,4 +2600,5 @@ void efl_ui_test_collection_view(TCase *tc)
    tcase_add_test(tc, test_efl_ui_collection_view_average_model_estimates);
    tcase_add_test(tc, test_efl_ui_collection_view_average_model_grid_prepend);
    tcase_add_test(tc, efl_ui_collection_view_lets_go_of_its_factory);
+   tcase_add_test(tc, efl_ui_collection_view_keeps_a_given_select_model);
 }

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.

Reply via email to