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 4f2fbd7ab6aba7c123d29e99fdfa44a55862b5bc
Author: Cedric BAIL <[email protected]>
AuthorDate: Sun Nov 8 11:24:09 2026 -0600

    elementary: a window gives back the content it unsets
    
    Efl.Ui.Win.content_unset took a reference of its own on the content, so
    a content removed with no replacement was never freed. Hand it back as
    a layout does: alive, no longer the window's child, holding no
    reference of ours. A content that is replaced is hidden and out of the
    box before the new one is taken, as Efl.Content says it is removed
    first.
    
    Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
 src/lib/elementary/efl_ui_win.c        | 45 +++++++++++++++++++++++++---------
 src/tests/elementary/efl_ui_test_win.c | 45 ++++++++++++++++++++++++++++++++++
 2 files changed, 78 insertions(+), 12 deletions(-)

diff --git a/src/lib/elementary/efl_ui_win.c b/src/lib/elementary/efl_ui_win.c
index ad81d1944a..eb775d2d40 100644
--- a/src/lib/elementary/efl_ui_win.c
+++ b/src/lib/elementary/efl_ui_win.c
@@ -7637,25 +7637,37 @@ _elm_win_standard_init(Eo *obj)
    _elm_win_frame_style_update(sd, 0, 1);
 }
 
+// Takes the content of the window out of it, and gives it back: still alive,
+// no longer the window's.
+static Eo *
+_win_content_detach(Efl_Ui_Win_Data *sd, Eo *obj)
+{
+   Eo *prev = sd->content;
+
+   if (!prev) return NULL;
+   efl_wref_del(prev, &sd->content);
+   sd->content = NULL;
+   evas_object_box_remove(sd->legacy.box, prev);
+   elm_widget_sub_object_del(obj, prev);
+   return prev;
+}
+
 static Eina_Bool
 _efl_ui_win_content_set(Eo *obj, Efl_Ui_Win_Data *sd, const char *part, Eo *content)
 {
+   Eo *prev;
+
    sd->legacy.forbidden = EINA_TRUE;
    if (eina_streq(part, "content"))
      {
         if (sd->content == content) return EINA_TRUE;
-        // The previous content goes first (@Efl.Content.content says so): left
-        // in the box, with its weak reference on, it would clear the slot of the
-        // content that replaced it when it is deleted.
-        if (sd->content)
-          {
-             Eo *prev = sd->content;
-
-             efl_wref_del(prev, &sd->content);
-             sd->content = NULL;
-             evas_object_box_remove(sd->legacy.box, prev);
-             elm_widget_sub_object_del(obj, prev);
-          }
+        // The previous content goes first, as @Efl.Content.content says: out of the
+        // box, hidden, and no longer held by the weak reference, which would
+        // clear the slot of the content that replaced it when it is deleted. It
+        // stays a child of the window, which ends it (callers that mean to keep
+        // it unset it first, and one that wants it gone deletes it).
+        prev = _win_content_detach(sd, obj);
+        if (prev && (prev != content)) evas_object_hide(prev);
         if (!content) return EINA_TRUE;
         if (!elm_widget_sub_object_add(obj, content))
           goto err;
@@ -7704,6 +7716,15 @@ _efl_ui_win_content_unset(Eo *obj, Efl_Ui_Win_Data *sd, const char *part)
    Eo *content;
 
    sd->legacy.forbidden = EINA_TRUE;
+   if (eina_streq(part, "content"))
+     {
+        // As Efl.Ui.Layout does: the caller gets the object alive and holding no
+        // reference of ours, and it is no longer a child of the window.
+        content = _win_content_detach(sd, obj);
+        if (content && (efl_parent_get(content) == obj))
+          efl_parent_set(content, evas_object_evas_get(obj));
+        return content;
+     }
    content = _efl_ui_win_content_get(obj, sd, part);
    if (!content) return NULL;
 
diff --git a/src/tests/elementary/efl_ui_test_win.c b/src/tests/elementary/efl_ui_test_win.c
index 0f242a577c..3eebd72861 100644
--- a/src/tests/elementary/efl_ui_test_win.c
+++ b/src/tests/elementary/efl_ui_test_win.c
@@ -705,6 +705,50 @@ EFL_START_TEST(efl_ui_win_test_event_forward_no_leak)
 }
 EFL_END_TEST
 
+// As Efl.Content says: a content that replaces another one removes it first
+// (it is hidden, the slot is the new one's, and deleting it later leaves the
+// slot alone), and the content that is unset is given back alive and alone,
+// holding nothing of the window's (as a layout does), so that deleting it
+// frees it.
+EFL_START_TEST(efl_ui_win_test_content_replace_and_unset)
+{
+   Efl_Ui_Win *win;
+   Eo *a, *b, *c, *gone = NULL, *got = NULL;
+
+   win = efl_new(EFL_UI_WIN_CLASS);
+   a = efl_add(EFL_UI_BUTTON_CLASS, win);
+   b = efl_add(EFL_UI_BUTTON_CLASS, win);
+   c = efl_add(EFL_UI_BUTTON_CLASS, win);
+   efl_wref_add(a, &gone);
+   efl_wref_add(c, &got);
+
+   ck_assert(efl_content_set(win, a));
+   ck_assert_ptr_eq(efl_content_get(win), a);
+   ck_assert(efl_content_set(win, b));
+   ck_assert_ptr_eq(efl_content_get(win), b);
+   ck_assert_ptr_ne(gone, NULL);
+   ck_assert(!efl_gfx_entity_visible_get(a));
+   efl_del(a);
+   ck_assert_ptr_eq(gone, NULL);
+   ck_assert_ptr_eq(efl_content_get(win), b);
+
+   ck_assert(efl_content_set(win, c));
+   ck_assert_ptr_eq(efl_content_get(win), c);
+   ck_assert_ptr_eq(efl_content_unset(win), c);
+   ck_assert_ptr_eq(efl_content_get(win), NULL);
+   // alive, and nobody has a reference but its parent
+   ck_assert_ptr_ne(got, NULL);
+   ck_assert_int_eq(efl_ref_count(c), 1);
+   ck_assert_ptr_ne(efl_parent_get(c), win);
+   efl_del(c);
+   ck_assert_ptr_eq(got, NULL);
+
+   // and a window that has none gives none
+   ck_assert_ptr_eq(efl_content_unset(win), NULL);
+   efl_unref(win);
+}
+EFL_END_TEST
+
 void
 efl_ui_test_win(TCase *tc)
 {
@@ -728,4 +772,5 @@ efl_ui_test_win(TCase *tc)
    tcase_add_test(tc, efl_ui_win_test_rotation_normalized);
    tcase_add_test(tc, efl_ui_win_test_type);
    tcase_add_test(tc, efl_ui_win_test_content_replaced);
+   tcase_add_test(tc, efl_ui_win_test_content_replace_and_unset);
 }

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

Reply via email to