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 b789822ab8e625a9d6f965fc117bdfdbc5e8f295
Author: Cedric BAIL <[email protected]>
AuthorDate: Sun Nov 15 20:45:13 2026 -0600
elementary: average_model: a row outliving the root does not reach it
The update of a row that was told its height holds a ref on the row,
which can outlive the root, and points at the root's totals, pending
list and self. A destructor on the root now marks every pending update
dropped and clears its root, and the clean of an update checks it. There
is no observable difference to be had in a test, the root being kept by
its rows in the cases tried; the test added is for valgrind.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
src/lib/elementary/efl_ui_average_model.c | 25 ++++++++++++++-
src/lib/elementary/efl_ui_average_model.eo | 1 +
src/tests/elementary/efl_ui_model.c | 49 ++++++++++++++++++++++++++++++
3 files changed, 74 insertions(+), 1 deletion(-)
diff --git a/src/lib/elementary/efl_ui_average_model.c b/src/lib/elementary/efl_ui_average_model.c
index b2dbbff928..4d4df65c52 100644
--- a/src/lib/elementary/efl_ui_average_model.c
+++ b/src/lib/elementary/efl_ui_average_model.c
@@ -49,6 +49,7 @@ struct _Efl_Ui_Average_Model_Update
unsigned int now;
// The row left, or the sizes were forgotten, before it was added: there is no row to add it to
Eina_Bool dropped : 1;
+ // (root is NULL once the root is gone: the row, which a ref keeps, outlives it)
};
// What an item is estimated to be, from what was told: not a number of its own,
@@ -107,7 +108,11 @@ _efl_ui_average_model_clean(Eo *obj, void *data, const Eina_Future *dead_future
{
Efl_Ui_Average_Model_Update *update = data;
- update->root->pending = eina_list_remove(update->root->pending, update);
+ // (a root that is gone has let go of its list, and says so with no root)
+ if (update->root)
+ {
+ update->root->pending = eina_list_remove(update->root->pending, update);
+ }
free(update);
efl_unref(obj);
@@ -298,6 +303,24 @@ _efl_ui_average_model_efl_model_property_get(const Eo *obj, Efl_Ui_Average_Model
return r;
}
+// The rows that were told something that was not added yet outlive the root
+// (the update holds a ref on its row): what they point at is gone with it.
+static void
+_efl_ui_average_model_efl_object_destructor(Eo *obj, Efl_Ui_Average_Model_Data *pd)
+{
+ Efl_Ui_Average_Model_Update *update;
+
+ EINA_LIST_FREE(pd->pending, update)
+ {
+ update->dropped = EINA_TRUE;
+ update->root = NULL;
+ update->total = NULL;
+ update->seen = NULL;
+ }
+
+ efl_destructor(efl_super(obj, EFL_UI_AVERAGE_MODEL_CLASS));
+}
+
static Efl_Object *
_efl_ui_average_model_efl_object_constructor(Eo *obj, Efl_Ui_Average_Model_Data *pd)
{
diff --git a/src/lib/elementary/efl_ui_average_model.eo b/src/lib/elementary/efl_ui_average_model.eo
index 9c1413995a..328c70db15 100644
--- a/src/lib/elementary/efl_ui_average_model.eo
+++ b/src/lib/elementary/efl_ui_average_model.eo
@@ -14,6 +14,7 @@ class @beta Efl.Ui.Average_Model extends Efl.Ui.Exact_Model
implements {
Efl.Object.constructor;
+ Efl.Object.destructor;
Efl.Model.property { set; get; }
}
}
diff --git a/src/tests/elementary/efl_ui_model.c b/src/tests/elementary/efl_ui_model.c
index 512bd0c2b6..6bb4c48f5d 100644
--- a/src/tests/elementary/efl_ui_model.c
+++ b/src/tests/elementary/efl_ui_model.c
@@ -817,6 +817,54 @@ EFL_START_TEST(efl_ui_average_model_remove_pending)
}
EFL_END_TEST
+// A row that was told its height, and whose model is deleted before the
+// loop gets to it, is not averaged into a model that is not there any more:
+// it must not write to it, tell of it or edit what it kept (valgrind sees it,
+// the rows being held by the test as they are by their updates).
+EFL_START_TEST(efl_ui_average_model_root_deleted)
+{
+ 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 model goes in the same turn, and the rows are still held
+ efl_del(model);
+ for (loops = 0; loops < 8; loops++)
+ {
+ ecore_main_loop_iterate();
+ }
+ // The two that were told are not averaged into what is gone
+ for (i = 0; i < 4; i++)
+ {
+ efl_unref(many->rows[i]);
+ }
+ for (loops = 0; loops < 8; loops++)
+ {
+ ecore_main_loop_iterate();
+ }
+
+ free(many);
+ efl_unref(base_model);
+}
+EFL_END_TEST
+
// A row that was removed has no place in the model any more: what is told
// to it is not for the row that is now at the index it had.
EFL_START_TEST(efl_ui_exact_model_removed_row_write)
@@ -1410,6 +1458,7 @@ efl_ui_model(TCase *tc)
tcase_add_test(tc, efl_ui_average_model_remove);
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_exact_model_test);
tcase_add_test(tc, efl_ui_exact_model_many_rows);
tcase_add_test(tc, efl_ui_exact_model_insert_remove);
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.