]> git.ipfire.org Git - thirdparty/dbus.git/commitdiff
Make sure a pending call timeout isn't assumed.
authorScott James Remnant <scott@ubuntu.com>
Mon, 11 May 2009 21:38:23 +0000 (22:38 +0100)
committerColin Walters <walters@verbum.org>
Tue, 14 Jul 2009 19:36:03 +0000 (15:36 -0400)
* dbus/dbus-connection.c (_dbus_connection_attach_pending_call_unlocked):
  Don't assume that the pending call has a timeout.
  (connection_timeout_and_complete_all_pending_call_unlocked): check that
  the timeout was actually added before removing it; this safeguards us
  if the pending call doesn't have a timeout.

Signed-off-by: Scott James Remnant <scott@ubuntu.com>
(cherry picked from commit ba22606c3b21c55c5c0af30d8f07edd71ded7213)

dbus/dbus-connection.c

index 947c0afee75b8323a9f15345f514f5f7f55a21ac..2530ad6a324fc94ef41d82c9b669de750541d115 100644 (file)
@@ -883,21 +883,34 @@ _dbus_connection_attach_pending_call_unlocked (DBusConnection  *connection,
 
   timeout = _dbus_pending_call_get_timeout_unlocked (pending);
 
-  if (!_dbus_connection_add_timeout_unlocked (connection, timeout))
-    return FALSE;
-  
-  if (!_dbus_hash_table_insert_int (connection->pending_replies,
-                                    reply_serial,
-                                    pending))
+  if (timeout)
     {
-      _dbus_connection_remove_timeout_unlocked (connection, timeout);
+      if (!_dbus_connection_add_timeout_unlocked (connection, timeout))
+        return FALSE;
+      
+      if (!_dbus_hash_table_insert_int (connection->pending_replies,
+                                        reply_serial,
+                                        pending))
+        {
+          _dbus_connection_remove_timeout_unlocked (connection, timeout);
 
-      _dbus_pending_call_set_timeout_added_unlocked (pending, FALSE);
-      HAVE_LOCK_CHECK (connection);
-      return FALSE;
+          _dbus_pending_call_set_timeout_added_unlocked (pending, FALSE);
+          HAVE_LOCK_CHECK (connection);
+          return FALSE;
+        }
+      
+      _dbus_pending_call_set_timeout_added_unlocked (pending, TRUE);
+    }
+  else
+    {
+      if (!_dbus_hash_table_insert_int (connection->pending_replies,
+                                        reply_serial,
+                                        pending))
+        {
+          HAVE_LOCK_CHECK (connection);
+          return FALSE;
+        }
     }
-  
-  _dbus_pending_call_set_timeout_added_unlocked (pending, TRUE);
 
   _dbus_pending_call_ref_unlocked (pending);
 
@@ -2188,8 +2201,10 @@ connection_timeout_and_complete_all_pending_calls_unlocked (DBusConnection *conn
        
       _dbus_pending_call_queue_timeout_error_unlocked (pending, 
                                                        connection);
-      _dbus_connection_remove_timeout_unlocked (connection,
-                                                _dbus_pending_call_get_timeout_unlocked (pending));
+
+      if (_dbus_pending_call_is_timeout_added_unlocked (pending))
+          _dbus_connection_remove_timeout_unlocked (connection,
+                                                    _dbus_pending_call_get_timeout_unlocked (pending));
       _dbus_pending_call_set_timeout_added_unlocked (pending, FALSE);       
       _dbus_hash_iter_remove_entry (&iter);