dbus_bus_register: don't unref the messages with the lock held
authorSimon McVittie <simon.mcvittie@collabora.co.uk>
Tue, 22 Feb 2011 18:49:29 +0000 (18:49 +0000)
committerSimon McVittie <simon.mcvittie@collabora.co.uk>
Thu, 28 Jul 2011 17:22:17 +0000 (18:22 +0100)
Finalizing a message can call out to user code via dbus_message_set_data
(or to internal code not expecting locks to be held, via DBusCounter).

Reviewed-by: Colin Walters <walters@verbum.org>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=34393

dbus/dbus-bus.c

index ea4b148..f05ddea 100644 (file)
@@ -661,6 +661,8 @@ dbus_bus_register (DBusConnection *connection,
   _dbus_return_val_if_error_is_set (error, FALSE);
 
   retval = FALSE;
+  message = NULL;
+  reply = NULL;
 
   _DBUS_LOCK (bus_datas);
 
@@ -668,18 +670,16 @@ dbus_bus_register (DBusConnection *connection,
   if (bd == NULL)
     {
       _DBUS_SET_OOM (error);
-      _DBUS_UNLOCK (bus_datas);
-      return FALSE;
+      goto out;
     }
 
   if (bd->unique_name != NULL)
     {
       _dbus_verbose ("Ignoring attempt to register the same DBusConnection %s with the message bus a second time.\n",
                      bd->unique_name);
-      _DBUS_UNLOCK (bus_datas);
-
       /* Success! */
-      return TRUE;
+      retval = TRUE;
+      goto out;
     }
   
   message = dbus_message_new_method_call (DBUS_SERVICE_DBUS,
@@ -690,15 +690,11 @@ dbus_bus_register (DBusConnection *connection,
   if (!message)
     {
       _DBUS_SET_OOM (error);
-
-      _DBUS_UNLOCK (bus_datas);
-      return FALSE;
+      goto out;
     }
   
   reply = dbus_connection_send_with_reply_and_block (connection, message, -1, error);
 
-  dbus_message_unref (message);
-  
   if (reply == NULL)
     goto out;
   else if (dbus_set_error_from_message (error, reply))
@@ -718,14 +714,17 @@ dbus_bus_register (DBusConnection *connection,
   retval = TRUE;
   
  out:
+  _DBUS_UNLOCK (bus_datas);
+
+  if (message)
+    dbus_message_unref (message);
+
   if (reply)
     dbus_message_unref (reply);
 
   if (!retval)
     _DBUS_ASSERT_ERROR_IS_SET (error);
 
-  _DBUS_UNLOCK (bus_datas);
-  
   return retval;
 }