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.
--- 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);
}