Don't free connection internals before it's closed. [#34]
authorMikael Hallendal <micke@imendio.com>
Sun, 30 Nov 2008 09:32:17 +0100
changeset 573 038320b7357e
parent 571 6fb1c4046db7
child 576 18caa29fe013
child 579 b1eec2598783
Don't free connection internals before it's closed. [#34] When the connection freed up internal states (in this case the handler lists) before closing itself it segfaulted when trying to unregister the SASL handlers. Reported by Julien Puydt.
loudmouth/lm-connection.c
--- 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);
     }