Merge branch 'dbus-1.4'
[platform/upstream/dbus.git] / 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;
 }