Fix the segfault when unloading the S5B module, by loading gio manually
authorGu1 <gu1@aeroxteam.fr>
Fri, 27 Aug 2010 11:19:32 +0200
changeset 163 a4c75fe75869
parent 162 6afab419ff88
child 164 6866328b34bd
Fix the segfault when unloading the S5B module, by loading gio manually committer: Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
jingle-s5b/socks5.c
jingle/register.c
--- a/jingle-s5b/socks5.c	Thu Aug 26 19:08:21 2010 +0200
+++ b/jingle-s5b/socks5.c	Fri Aug 27 11:19:32 2010 +0200
@@ -509,7 +509,18 @@
 
 static void jingle_socks5_init(void)
 {
-  g_type_init();
+  // ugly hack to fix the segfault when quitting:
+  // mcabber doesn't load gthread or gobject but they are required by gio,
+  // and cannot be unloaded once they are loaded or a segfault occur.
+  // We dlopen gio with global | nodelete flags. This will also load gobject
+  // and gthread as dependencies. g_type_init will init gobject/gthread (and
+  // set threads_got_initialized to true).
+  if (g_threads_got_initialized == FALSE) {
+    void *dlopen(const char *filename, int flag);
+    // RTLD_LAZY | RTLD_GLOBAL | RTLD_NODELETE
+    dlopen("libgio-2.0.so", 0x00001 | 0x00100 | 0x01000);
+    g_type_init();
+  }
   jingle_register_transport(NS_JINGLE_TRANSPORT_SOCKS5, &funcs,
                             JINGLE_TRANSPORT_STREAMING,
                             JINGLE_TRANSPORT_PRIO_HIGH);
--- a/jingle/register.c	Thu Aug 26 19:08:21 2010 +0200
+++ b/jingle/register.c	Fri Aug 27 11:19:32 2010 +0200
@@ -191,6 +191,6 @@
   TransportHandlerEntry *entry = jingle_find_transport(xmlns);
   if (entry) {
     jingle_free_transport(entry);
-    jingle_transport_handlers = g_slist_remove(jingle_app_handlers, entry);
+    jingle_transport_handlers = g_slist_remove(jingle_transport_handlers, entry);
   }
 }