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 2c1da0e2b2d7de882baf7249ffcfbc275c0258ed
Author: Cedric BAIL <[email protected]>
AuthorDate: Tue Nov 10 22:17:37 2026 -0600

    elementary: average_model: release a pending height's ref from a job
    
    The update of a row that was told its height holds a ref on the row and
    lets go of it when its future is freed. If that was the last ref, the
    row was destroyed from inside the free: it cancels the futures it is the
    object of, this one among them, and _eina_future_free wrote to a future
    that was being freed (invalid write under valgrind). The ref is now let
    go of from the free of a job future of the loop, where nothing of the
    first future is left.
    
    The test sets heights and drops every user ref in the same turn; it is
    the valgrind invalid write before, and checks the average that was
    added.
    
    Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
 src/lib/elementary/efl_ui_average_model.c | 15 ++++++++++-
 src/tests/elementary/efl_ui_model.c       | 45 +++++++++++++++++++++++++++++++
 2 files changed, 59 insertions(+), 1 deletion(-)

diff --git a/src/lib/elementary/efl_ui_average_model.c b/src/lib/elementary/efl_ui_average_model.c
index 9486fad2f4..a718557f7c 100644
--- a/src/lib/elementary/efl_ui_average_model.c
+++ b/src/lib/elementary/efl_ui_average_model.c
@@ -112,6 +112,13 @@ _efl_ui_average_model_update(Eo *obj EINA_UNUSED, void *data, const Eina_Value v
    return v;
 }
 
+static void
+_efl_ui_average_model_unref(Eo *loop EINA_UNUSED, void *data,
+                            const Eina_Future *dead_future EINA_UNUSED)
+{
+   efl_unref(data);
+}
+
 static void
 _efl_ui_average_model_clean(Eo *obj, void *data, const Eina_Future *dead_future EINA_UNUSED)
 {
@@ -124,7 +131,13 @@ _efl_ui_average_model_clean(Eo *obj, void *data, const Eina_Future *dead_future
      }
    free(update);
 
-   efl_unref(obj);
+   // This is called from inside the freeing of the future, which the row
+   // being the last ref of is destroyed under: the row cancels the futures it
+   // is the object of, this one among them, and it is freed twice. The ref is
+   // let go of from a job, where nothing of that future is left to be touched
+   // (the job is freed, and so the ref is let go of, even if the loop goes first).
+   efl_future_then(efl_loop_get(obj), efl_loop_job(efl_loop_get(obj)),
+                   .data = "" .free = _efl_ui_average_model_unref);
 }
 
 static Eina_Future *
diff --git a/src/tests/elementary/efl_ui_model.c b/src/tests/elementary/efl_ui_model.c
index 9aff84ad98..119e754017 100644
--- a/src/tests/elementary/efl_ui_model.c
+++ b/src/tests/elementary/efl_ui_model.c
@@ -865,6 +865,50 @@ EFL_START_TEST(efl_ui_average_model_root_deleted)
 }
 EFL_END_TEST
 
+// The last ref to a row that was told its height is dropped in the same turn:
+// the ref the pending update holds is then the last one, and it must not be
+// let go of while the future that holds the update is being freed (valgrind
+// sees the row, and the future with it, being destroyed from inside it).
+EFL_START_TEST(efl_ui_average_model_last_ref_dropped)
+{
+   Efl_Model *base_model, *model;
+   Many_Rows *many = calloc(1, sizeof (Many_Rows));
+   unsigned int i, loops;
+
+   base_model = efl_add_ref(EFL_GENERIC_MODEL_CLASS, efl_main_loop_get());
+   for (i = 0; i < 4; i++)
+     {
+        efl_model_child_add(base_model);
+     }
+   model = efl_add_ref(EFL_UI_AVERAGE_MODEL_CLASS, efl_main_loop_get(),
+                       efl_ui_view_model_set(efl_added, base_model));
+   ck_assert(!!model);
+   eina_future_then(efl_model_children_slice_get(model, 0, 4), _many_rows_then, many, NULL);
+   for (loops = 0; (loops < 50) && many->count < 4; loops++)
+     {
+        ecore_main_loop_iterate();
+     }
+   ck_assert_uint_eq(many->count, 4);
+
+   _uint_set(many->rows[0], "self.height", 40);
+   _uint_set(many->rows[1], "self.height", 10);
+   // The user lets go in the same turn: only the updates hold the rows now
+   for (i = 0; i < 4; i++)
+     {
+        efl_unref(many->rows[i]);
+     }
+   for (loops = 0; loops < 8; loops++)
+     {
+        ecore_main_loop_iterate();
+     }
+   ck_assert_uint_eq(_property_uint_expected(model, "total.height"), 100);
+
+   free(many);
+   efl_unref(model);
+   efl_unref(base_model);
+}
+EFL_END_TEST
+
 static void
 _total_height_changed(void *data, const Efl_Event *ev)
 {
@@ -1605,6 +1649,7 @@ efl_ui_model(TCase *tc)
    tcase_add_test(tc, efl_ui_average_model_shrink);
    tcase_add_test(tc, efl_ui_average_model_remove_pending);
    tcase_add_test(tc, efl_ui_average_model_root_deleted);
+   tcase_add_test(tc, efl_ui_average_model_last_ref_dropped);
    tcase_add_test(tc, efl_ui_average_model_first_measure);
    tcase_add_test(tc, efl_ui_exact_model_test);
    tcase_add_test(tc, efl_ui_exact_model_many_rows);

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

Reply via email to