jackdanielz pushed a commit to branch master.

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

commit 3235c83c360988603765d6b781aae65e0d7e6618
Author: Daniel Zaoui <[email protected]>
Date:   Fri Dec 23 22:53:52 2016 +0200

    Ecore_Con_Url/Curl: add referencing on _c structure
    
    The _c structure used to store the Curl function pointers needs
    referencing to be sure it is not freed although still needed.
    The non-referencing was leading to a crash during the destruction
    of the dialers. The _c was still used although it has been freed
    by ecore_con_url_shutdown.
---
 src/lib/ecore_con/ecore_con_url_curl.c | 9 +++++++--
 src/lib/ecore_con/ecore_con_url_curl.h | 2 ++
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/src/lib/ecore_con/ecore_con_url_curl.c 
b/src/lib/ecore_con/ecore_con_url_curl.c
index 4b325a1..e0d5f93 100644
--- a/src/lib/ecore_con/ecore_con_url_curl.c
+++ b/src/lib/ecore_con/ecore_con_url_curl.c
@@ -244,7 +244,11 @@ _c_init(void)
 {
    long ms = 0;
 
-   if (_c) return EINA_TRUE;
+   if (_c)
+     {
+        _c->ref++;
+        return EINA_TRUE;
+     }
    if (_c_fail)
      {
         ERR("Cannot find libcurl at runtime!");
@@ -252,6 +256,7 @@ _c_init(void)
      }
    _c = calloc(1, sizeof(Ecore_Con_Curl));
    if (!_c) goto error;
+   _c->ref++;
 
 #define LOAD(x)                               \
   if (!_c->mod) {                             \
@@ -342,7 +347,7 @@ error:
 void
 _c_shutdown(void)
 {
-   if (!_c) return;
+   if (!_c || _c->ref--) return;
    if (_c->_curlm)
      {
         _c->curl_multi_cleanup(_c->_curlm);
diff --git a/src/lib/ecore_con/ecore_con_url_curl.h 
b/src/lib/ecore_con/ecore_con_url_curl.h
index 42eae54..ae79c4c 100644
--- a/src/lib/ecore_con/ecore_con_url_curl.h
+++ b/src/lib/ecore_con/ecore_con_url_curl.h
@@ -451,6 +451,8 @@ struct _Ecore_Con_Curl
                                                 const char *string);
    time_t                  (*curl_getdate)(const char *p, const time_t 
*unused);
    curl_version_info_data *(*curl_version_info)(CURLversion);
+
+   int                     ref; /* Reference on the structure */
 };
 
 #define CURL_MIN_TIMEOUT 100

-- 


Reply via email to