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 294cc241ce4c81673520eefeaf3ca49d0068f2dc
Author: Cedric BAIL <[email protected]>
AuthorDate: Sat Nov 7 23:41:00 2026 -0600

    ecore: an environment object frees its variables when it is deleted
    
    Efl.Core.Env made its hash in the constructor and had no destructor, so
    every environment object, and every duplicate of one, lost its table and
    the values in it. The destructor frees it.
    
    The test makes and deletes 200 environments of sixteen variables of a
    kilobyte, with a duplicate of each, twice over, and checks that the
    heap does not grow the second time; without the destructor it grows by
    1.6 MB. It checks nothing where glibc has no mallinfo2().
    
    Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
 src/lib/ecore/efl_core_env.c       |  9 +++++++
 src/lib/ecore/efl_core_env.eo      |  1 +
 src/tests/ecore/efl_app_test_env.c | 55 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 65 insertions(+)

diff --git a/src/lib/ecore/efl_core_env.c b/src/lib/ecore/efl_core_env.c
index 1a4de58c91..3699a89eea 100644
--- a/src/lib/ecore/efl_core_env.c
+++ b/src/lib/ecore/efl_core_env.c
@@ -94,6 +94,15 @@ _efl_core_env_efl_object_constructor(Eo *obj, Efl_Core_Env_Data *pd)
    return efl_constructor(efl_super(obj, MY_CLASS));
 }
 
+EOLIAN static void
+_efl_core_env_efl_object_destructor(Eo *obj, Efl_Core_Env_Data *pd)
+{
+   eina_hash_free(pd->env);
+   pd->env = NULL;
+
+   efl_destructor(efl_super(obj, MY_CLASS));
+}
+
 EOLIAN static Eina_Iterator*
 _efl_core_env_content_get(const Eo *obj EINA_UNUSED, Efl_Core_Env_Data *pd)
 {
diff --git a/src/lib/ecore/efl_core_env.eo b/src/lib/ecore/efl_core_env.eo
index c17e0a1440..22a4ccc886 100644
--- a/src/lib/ecore/efl_core_env.eo
+++ b/src/lib/ecore/efl_core_env.eo
@@ -53,6 +53,7 @@ class @beta Efl.Core.Env extends Efl.Object implements Efl.Duplicate {
    }
    implements {
       Efl.Object.constructor;
+      Efl.Object.destructor;
       Efl.Duplicate.duplicate;
    }
 }
diff --git a/src/tests/ecore/efl_app_test_env.c b/src/tests/ecore/efl_app_test_env.c
index e7e5a2e034..cf7c0b8f62 100644
--- a/src/tests/ecore/efl_app_test_env.c
+++ b/src/tests/ecore/efl_app_test_env.c
@@ -3,7 +3,14 @@
 #endif
 
 #include <stdio.h>
+#include <string.h>
 #include <unistd.h>
+#if defined(__GLIBC__) && defined(__GLIBC_PREREQ)
+# if __GLIBC_PREREQ(2, 33)
+#  include <malloc.h>
+#  define HAVE_MALLINFO2
+# endif
+#endif
 #define EFL_NOLEGACY_API_SUPPORT
 #include <Efl_Core.h>
 #include "efl_app_suite.h"
@@ -124,6 +131,53 @@ EFL_START_TEST(efl_core_env_test_undepend_fork)
 }
 EFL_END_TEST
 
+/* 200 environments of 16 variables of a kilobyte each, and a duplicate of each,
+ * made and deleted. */
+static void
+_env_churn(void)
+{
+   char name[32], value[1024];
+   int n, i;
+
+   memset(value, 'v', sizeof(value) - 1);
+   value[sizeof(value) - 1] = '\0';
+   for (n = 0; n < 200; n++)
+     {
+        Efl_Core_Env *env = efl_add_ref(EFL_CORE_ENV_CLASS, NULL), *copy;
+
+        for (i = 0; i < 16; i++)
+          {
+             snprintf(name, sizeof(name), "VAR_%d_%d", n, i);
+             value[0] = 'a' + i;
+             efl_core_env_set(env, name, value);
+          }
+        copy = efl_duplicate(env);
+        snprintf(name, sizeof(name), "VAR_%d_3", n);
+        ck_assert_int_eq(efl_core_env_get(copy, name)[0], 'd');
+        efl_unref(env);
+        efl_unref(copy);
+     }
+}
+
+EFL_START_TEST(efl_core_env_test_destroyed_with_values)
+{
+#ifdef HAVE_MALLINFO2
+   size_t before, after;
+
+   /* A deleted environment gives its variables back. What a leak keeps shows in
+    * the heap: 200 environments with 16 values of a kilobyte, twice over, are
+    * megabytes, and the heap must not grow by a fraction of that. */
+   _env_churn();
+   before = mallinfo2().uordblks;
+   _env_churn();
+   after = mallinfo2().uordblks;
+   ck_assert_msg(after < before + 256 * 1024, "the heap grew by %zu bytes", after - before);
+#else
+   _env_churn();
+#endif
+}
+EFL_END_TEST
+
 void efl_test_efl_env(TCase *tc)
 {
    tcase_add_test(tc, efl_core_env_test_set_get);
@@ -132,4 +186,5 @@ void efl_test_efl_env(TCase *tc)
    tcase_add_test(tc, efl_core_env_test_fork);
    tcase_add_test(tc, efl_core_env_test_process);
    tcase_add_test(tc, efl_core_env_test_undepend_fork);
+   tcase_add_test(tc, efl_core_env_test_destroyed_with_values);
 }

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

Reply via email to