From 15e114b6989d474f12e1e64d74467916392b6977 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Tue, 22 Feb 2011 18:49:29 +0000 Subject: [PATCH 02/10] dbus_bus_register: don't unref the messages with the lock held 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). --- dbus/dbus-bus.c | 23 +++++++++++------------ 1 files changed, 11 insertions(+), 12 deletions(-) diff --git a/dbus/dbus-bus.c b/dbus/dbus-bus.c index 8cb82eb..9218e12 100644 --- a/dbus/dbus-bus.c +++ b/dbus/dbus-bus.c @@ -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; } -- 1.7.4.1