loudmouth/lm-connection.c
changeset 573 038320b7357e
parent 545 58954d98a7f9
child 600 7f0be2600f6d
--- a/loudmouth/lm-connection.c	Tue Nov 25 17:28:27 2008 +0100
+++ b/loudmouth/lm-connection.c	Sun Nov 30 09:32:17 2008 +0100
@@ -253,6 +253,14 @@
 static void
 connection_free (LmConnection *connection)
 {
+    /* This needs to be run before starting to free internal states.
+     * It used to be run after the handlers where freed which lead to a crash
+     * when the connection was freed prior to running lm_connection_close.
+     */
+    if (connection->state >= LM_CONNECTION_STATE_OPENING) {
+        connection_do_close (connection);
+    }
+
     g_free (connection->server);
     g_free (connection->jid);
     g_free (connection->effective_jid);
@@ -270,10 +278,7 @@
     connection_free_handlers (connection);
     
     g_hash_table_destroy (connection->id_handlers);
-    if (connection->state >= LM_CONNECTION_STATE_OPENING) {
-        connection_do_close (connection);
-    }
-
+    
     if (connection->open_cb) {
         _lm_utils_free_callback (connection->open_cb);
     }