jpeg pushed a commit to branch master.

http://git.enlightenment.org/core/efl.git/commit/?id=e47edc250dc715a6b0f94be4b1cb81d32e9d97fe

commit e47edc250dc715a6b0f94be4b1cb81d32e9d97fe
Author: Jean-Philippe Andre <jp.an...@samsung.com>
Date:   Tue Dec 29 20:29:36 2015 +0900

    Eo: Prevent shutdown from actually doing anything
    
    Currently, eo_shutdown can't work.
    
    Every Eo_Class ID is stored inside its class_get() function as a
    static variable. This means any call to class_get() after eo_shutdown()
    (even if eo_init was done properly) will lead to using an invalid ref
    for the class id. In other words, the class is not valid anymore,
    and objects can't be created.
    
    Resetting the pointer to NULL would be possible, if we passed it
    during the class creation. But this would lead to potential crashes
    if a class was created from a now dlclosed library.
    
    The only solution I can envision here is to check that class_get
    actually returns a valid ref with the right class name. Most likely
    the performance impact is not acceptable.
    
    This fixes make check for me (with systemd module for ecore).
---
 src/lib/eo/eo.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/src/lib/eo/eo.c b/src/lib/eo/eo.c
index fd1fc2a..ef4a625 100644
--- a/src/lib/eo/eo.c
+++ b/src/lib/eo/eo.c
@@ -1849,10 +1849,21 @@ eo_shutdown(void)
 {
    size_t i;
    _Eo_Class **cls_itr = _eo_classes;
+   const char *s;
 
+   EINA_SAFETY_ON_FALSE_RETURN_VAL(_eo_init_count > 0, EINA_FALSE);
    if (--_eo_init_count > 0)
      return EINA_TRUE;
 
+   /* We can't actually shutdown Eo for similar reasons that closing a
+    * shared library is risky: all Eo_Class IDs are stored inside their
+    * classname_get() function and can't be safely reset to NULL. */
+   if (!(s = getenv("EO_SHUTDOWN_ENABLE")) || (atoi(s) != 1))
+     {
+        _eo_init_count = 1;
+        return EINA_TRUE;
+     }
+
    eina_log_timing(_eo_log_dom,
                    EINA_LOG_STATE_START,
                    EINA_LOG_STATE_SHUTDOWN);
@@ -1872,7 +1883,10 @@ eo_shutdown(void)
    eina_spinlock_free(&_eo_class_creation_lock);
 
    if (_eo_call_stack_key != 0)
-     eina_tls_free(_eo_call_stack_key);
+     {
+        eina_tls_free(_eo_call_stack_key);
+        _eo_call_stack_key = 0;
+     }
 
    _eo_free_ids_tables();
 

-- 


Reply via email to