efl_net_server_ssl: monitor context del and unref on destructor.
authorGustavo Sverzut Barbieri <barbieri@profusion.mobi>
Thu, 8 Dec 2016 17:25:11 +0000 (15:25 -0200)
committerGustavo Sverzut Barbieri <barbieri@profusion.mobi>
Thu, 8 Dec 2016 18:00:01 +0000 (16:00 -0200)
we're leaking ssl_ctx on destruction, also monitor it so we don't
access stale data.

src/lib/ecore_con/efl_net_server_ssl.c

index 91810ea..1fe34bc 100644 (file)
@@ -150,6 +150,14 @@ _efl_net_server_ssl_efl_object_constructor(Eo *o, Efl_Net_Server_Ssl_Data *pd)
    return o;
 }
 
+static void
+_efl_net_server_ssl_ctx_del(void *data, const Efl_Event *event EINA_UNUSED)
+{
+   Eo *o = data;
+   Efl_Net_Server_Ssl_Data *pd = efl_data_scope_get(o, MY_CLASS);
+   pd->ssl_ctx = NULL;
+}
+
 EOLIAN void
 _efl_net_server_ssl_efl_object_destructor(Eo *o, Efl_Net_Server_Ssl_Data *pd)
 {
@@ -159,6 +167,13 @@ _efl_net_server_ssl_efl_object_destructor(Eo *o, Efl_Net_Server_Ssl_Data *pd)
         pd->server = NULL;
      }
 
+   if (pd->ssl_ctx)
+     {
+        efl_event_callback_del(pd->ssl_ctx, EFL_EVENT_DEL, _efl_net_server_ssl_ctx_del, o);
+        efl_unref(pd->ssl_ctx);
+        pd->ssl_ctx = NULL;
+     }
+
    efl_destructor(efl_super(o, MY_CLASS));
 }
 
@@ -170,6 +185,8 @@ _efl_net_server_ssl_ssl_context_set(Eo *o EINA_UNUSED, Efl_Net_Server_Ssl_Data *
    if (pd->ssl_ctx == ssl_ctx) return;
    efl_unref(pd->ssl_ctx);
    pd->ssl_ctx = efl_ref(ssl_ctx);
+   if (ssl_ctx)
+     efl_event_callback_add(ssl_ctx, EFL_EVENT_DEL, _efl_net_server_ssl_ctx_del, o);
 }
 
 EOLIAN static Eo *