2006-05-26 Mikael Hallendal <micke@imendio.com>
authorhallski <hallski>
Fri, 26 May 2006 14:16:56 +0000 (14:16 +0000)
committerhallski <hallski>
Fri, 26 May 2006 14:16:56 +0000 (14:16 +0000)
* 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.

ChangeLog
loudmouth/lm-connection.c

index 54ceb3d924df2a56296b84772401375ff71f0d9c..9ad6599346c8926013a866bb142c5e68c4265c6e 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2006-05-26  Mikael Hallendal  <micke@imendio.com>
+
+       * 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  <micke@imendio.com>
 
        * Release 1.1.1
index 598aabd17754033707e8cfb47475e5c857b40f28..f7f8d43e6e00e32fae24828360888b039e653104 100644 (file)
@@ -81,9 +81,9 @@ struct _LmConnection {
        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_free (LmConnection *connection)
                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 @@ connection_handle_message (LmConnection *connection, LmMessage *m)
        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 @@ connection_handle_message (LmConnection *connection, LmMessage *m)
        }
        
        if (result == LM_HANDLER_RESULT_REMOVE_MESSAGE) {
-               return;
+               goto out;
        }
 
        for (l = connection->handlers[lm_message_get_type (m)]; 
@@ -282,6 +294,9 @@ connection_handle_message (LmConnection *connection, LmMessage *m)
                                                             connection,
                                                             m);
        }
+
+out:
+       lm_connection_unref (connection);
        
        return;
 }
@@ -456,11 +471,14 @@ _lm_connection_failed_with_error (LmConnectData *connect_data, int error)
        
        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 (LmConnectData *connect_data)
        _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 @@ connection_auth_reply (LmMessageHandler *handler,
        
        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;
 
-               (* ((LmResultFunction) cb->func)) (connection, 
-                                                  result, cb->user_data);
+               connection->auth_cb = NULL;
+
+               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_stream_received (LmConnection *connection, LmMessage *m)
 
        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_connection_set_disconnect_function (LmConnection         *connection,
                _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;
+       }
 }
 
 /**