# HG changeset patch # User hallski # Date 1148653016 0 # Node ID 92193c23b0c7cb17e68c3666c53008399b60cf6e # Parent f8b4c3dc5630a9ab19fec0bc1ec2b69c583ab908 2006-05-26 Mikael Hallendal * loudmouth/lm-connection.c: (connection_free), (connection_handle_message), (_lm_connection_failed_with_error), (connection_auth_reply), (connection_stream_received), (lm_connection_set_disconnect_function): - Patch from Owen Taylor fixes two reentrancy problems. - Fixes LM-37. diff -r f8b4c3dc5630 -r 92193c23b0c7 ChangeLog --- a/ChangeLog Thu May 04 13:15:25 2006 +0000 +++ b/ChangeLog Fri May 26 14:16:56 2006 +0000 @@ -1,3 +1,12 @@ +2006-05-26 Mikael Hallendal + + * loudmouth/lm-connection.c: (connection_free), + (connection_handle_message), (_lm_connection_failed_with_error), + (connection_auth_reply), (connection_stream_received), + (lm_connection_set_disconnect_function): + - Patch from Owen Taylor fixes two reentrancy problems. + - Fixes LM-37. + 2006-04-19 Mikael Hallendal * Release 1.1.1 diff -r f8b4c3dc5630 -r 92193c23b0c7 loudmouth/lm-connection.c --- a/loudmouth/lm-connection.c Thu May 04 13:15:25 2006 +0000 +++ b/loudmouth/lm-connection.c Fri May 26 14:16:56 2006 +0000 @@ -81,9 +81,9 @@ gboolean blocking; gboolean cancel_open; - LmCallback *close_cb; + LmCallback *close_cb; /* unused */ LmCallback *auth_cb; - LmCallback *register_cb; + LmCallback *register_cb; /* unused */ LmCallback *disconnect_cb; @@ -223,6 +223,16 @@ connection_do_close (connection); } + if (connection->open_cb) { + _lm_utils_free_callback (connection->open_cb); + } + + if (connection->auth_cb) { + _lm_utils_free_callback (connection->auth_cb); + } + + lm_connection_set_disconnect_function (connection, NULL, NULL, NULL); + while ((m = g_queue_pop_head (connection->incoming_messages)) != NULL) { lm_message_unref (m); } @@ -252,9 +262,11 @@ const gchar *id; LmHandlerResult result = LM_HANDLER_RESULT_ALLOW_MORE_HANDLERS; + lm_connection_ref (connection); + if (lm_message_get_type (m) == LM_MESSAGE_TYPE_STREAM) { connection_stream_received (connection, m); - return; + goto out; } id = lm_message_node_get_attribute (m->node, "id"); @@ -270,7 +282,7 @@ } if (result == LM_HANDLER_RESULT_REMOVE_MESSAGE) { - return; + goto out; } for (l = connection->handlers[lm_message_get_type (m)]; @@ -282,6 +294,9 @@ connection, m); } + +out: + lm_connection_unref (connection); return; } @@ -456,11 +471,14 @@ if (connect_data->current_addr == NULL) { connection_do_close (connection); - if (connection->open_cb && connection->open_cb->func) { + if (connection->open_cb) { LmCallback *cb = connection->open_cb; + + connection->open_cb = NULL; (* ((LmResultFunction) cb->func)) (connection, FALSE, cb->user_data); + _lm_utils_free_callback (cb); } freeaddrinfo (connect_data->resolved_addrs); @@ -477,7 +495,7 @@ _lm_connection_failed_with_error (connect_data, _lm_sock_get_last_error()); } - + static gboolean connection_connect_cb (GIOChannel *source, GIOCondition condition, @@ -1299,16 +1317,19 @@ lm_verbose ("AUTH reply: %d\n", result); - if (connection->auth_cb && connection->auth_cb->func) { - LmCallback *cb = connection->auth_cb; + if (connection->auth_cb) { + LmCallback *cb = connection->auth_cb; + + connection->auth_cb = NULL; - (* ((LmResultFunction) cb->func)) (connection, - result, cb->user_data); + if (cb->func) { + (* ((LmResultFunction) cb->func)) (connection, + result, cb->user_data); + } + + _lm_utils_free_callback (cb); } - _lm_utils_free_callback (connection->auth_cb); - connection->auth_cb = NULL; - return LM_HANDLER_RESULT_REMOVE_MESSAGE; } @@ -1333,15 +1354,18 @@ connection_start_keep_alive (connection); - if (connection->open_cb && connection->open_cb->func) { + if (connection->open_cb) { LmCallback *cb = connection->open_cb; + + connection->open_cb = NULL; - (* ((LmResultFunction) cb->func)) (connection, result, - cb->user_data); + if (cb->func) { + (* ((LmResultFunction) cb->func)) (connection, result, + cb->user_data); + + } + _lm_utils_free_callback (connection->open_cb); } - - _lm_utils_free_callback (connection->open_cb); - connection->open_cb = NULL; } static gint @@ -2264,9 +2288,13 @@ _lm_utils_free_callback (connection->disconnect_cb); } - connection->disconnect_cb = _lm_utils_new_callback (function, - user_data, - notify); + if (function) { + connection->disconnect_cb = _lm_utils_new_callback (function, + user_data, + notify); + } else { + connection->disconnect_cb = NULL; + } } /**