# HG changeset patch # User Mikael Hallendal # Date 1228033937 -3600 # Node ID 038320b7357e4e1ca33ab8ff3e5e9ec0e741a9fe # Parent 6fb1c4046db71e11a6dbd43827556c0e07bc84c4 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. diff -r 6fb1c4046db7 -r 038320b7357e 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); }