diff options
author | Joe Shaw <joeshaw@novell.com> | 2005-03-08 20:42:21 +0000 |
---|---|---|
committer | Joe Shaw <joeshaw@novell.com> | 2005-03-08 20:42:21 +0000 |
commit | 08c57f6c92d6511466b7d255e0724a961a99d303 (patch) | |
tree | ba8ba2e5edc2f658901fa3caacc67bcf428856bd | |
parent | 76dbc207a8665ee85790ccecbda4f172a9c72d27 (diff) | |
download | dbus-08c57f6c92d6511466b7d255e0724a961a99d303.tar.gz |
2005-03-08 Joe Shaw <joeshaw@novell.com>
* dbus/dbus-connection.c (dbus_connection_send_with_reply):
After we attach our pending call to the connection, unref
it. Fixes a leak.
* dbus/dbus-pending-call.c (dbus_pending_call_get_reply):
Add this back. Accidentally broke API/ABI compat.
* mono/Connection.cs (set_RawConnection): Disconnect our
filter and match callbacks from the old connection and
reconnect them to the new connection, if any.
* mono/DBusType/ObjectPath.cs (ctor): Don't leak the
object path that we get back from unmanaged code.
(Append): Don't leak the object path that we pass
into unmanaged code.
* mono/DBusType/String.cs (ctor): Don't leak the string
that we get back from unmanaged code.
(Append): Don't leak the string that we pass into
unmanaged code.
-rw-r--r-- | ChangeLog | 23 | ||||
-rw-r--r-- | dbus/dbus-connection.c | 2 | ||||
-rw-r--r-- | dbus/dbus-pending-call.c | 18 | ||||
-rw-r--r-- | mono/Connection.cs | 19 | ||||
-rw-r--r-- | mono/DBusType/ObjectPath.cs | 16 | ||||
-rw-r--r-- | mono/DBusType/String.cs | 14 |
6 files changed, 87 insertions, 5 deletions
@@ -1,3 +1,26 @@ +2005-03-08 Joe Shaw <joeshaw@novell.com> + + * dbus/dbus-connection.c (dbus_connection_send_with_reply): + After we attach our pending call to the connection, unref + it. Fixes a leak. + + * dbus/dbus-pending-call.c (dbus_pending_call_get_reply): + Add this back. Accidentally broke API/ABI compat. + + * mono/Connection.cs (set_RawConnection): Disconnect our + filter and match callbacks from the old connection and + reconnect them to the new connection, if any. + + * mono/DBusType/ObjectPath.cs (ctor): Don't leak the + object path that we get back from unmanaged code. + (Append): Don't leak the object path that we pass + into unmanaged code. + + * mono/DBusType/String.cs (ctor): Don't leak the string + that we get back from unmanaged code. + (Append): Don't leak the string that we pass into + unmanaged code. + 2005-02-22 Joe Shaw <joeshaw@novell.com> * python/dbus_bindings.pyx.in: API changed, so call diff --git a/dbus/dbus-connection.c b/dbus/dbus-connection.c index 46e0c52b..89f789b3 100644 --- a/dbus/dbus-connection.c +++ b/dbus/dbus-connection.c @@ -2141,6 +2141,8 @@ dbus_connection_send_with_reply (DBusConnection *connection, if (!_dbus_connection_attach_pending_call_unlocked (connection, pending)) goto error; + + dbus_pending_call_unref (pending); if (!_dbus_connection_send_unlocked_no_update (connection, message, NULL)) { diff --git a/dbus/dbus-pending-call.c b/dbus/dbus-pending-call.c index 546f42a6..3844e473 100644 --- a/dbus/dbus-pending-call.c +++ b/dbus/dbus-pending-call.c @@ -291,6 +291,24 @@ dbus_pending_call_steal_reply (DBusPendingCall *pending) } /** + * Gets the reply, or returns #NULL if none has been received yet. The + * reference count is not incremented on the returned message, so you + * have to keep a reference count on the pending call (or add one + * to the message). + * + * @todo not thread safe? I guess it has to lock though it sucks + * @todo maybe to make this threadsafe, it should be steal_reply(), i.e. only one thread can ever get the message + * + * @param pending the pending call + * @returns the reply message or #NULL. + */ +DBusMessage* +dbus_pending_call_get_reply (DBusPendingCall *pending) +{ + return pending->reply; +} + +/** * Block until the pending call is completed. The blocking is as with * dbus_connection_send_with_reply_and_block(); it does not enter the * main loop or process other messages, it simply waits for the reply diff --git a/mono/Connection.cs b/mono/Connection.cs index 5eb4a9f4..bcd06e4a 100644 --- a/mono/Connection.cs +++ b/mono/Connection.cs @@ -171,6 +171,13 @@ namespace DBus if (rawConnection != IntPtr.Zero) { + // Remove our callbacks from this connection + foreach (DBusHandleMessageFunction func in this.filters) + dbus_connection_remove_filter (rawConnection, func, IntPtr.Zero); + + foreach (string match_rule in this.matches) + dbus_bus_remove_match (rawConnection, match_rule, IntPtr.Zero); + // Get the reference to this IntPtr rawThis = dbus_connection_get_data (rawConnection, Slot); Debug.Assert (rawThis != IntPtr.Zero); @@ -197,6 +204,18 @@ namespace DBus rawThis = GCHandle.Alloc (this, GCHandleType.WeakTrackResurrection); dbus_connection_set_data(rawConnection, Slot, (IntPtr) rawThis, IntPtr.Zero); + + // Add the callbacks to this new connection + foreach (DBusHandleMessageFunction func in this.filters) + dbus_connection_add_filter (rawConnection, func, IntPtr.Zero, IntPtr.Zero); + + foreach (string match_rule in this.matches) + dbus_bus_add_match (rawConnection, match_rule, IntPtr.Zero); + } + else + { + this.filters.Clear (); + this.matches.Clear (); } } } diff --git a/mono/DBusType/ObjectPath.cs b/mono/DBusType/ObjectPath.cs index f82c6804..38952f4e 100644 --- a/mono/DBusType/ObjectPath.cs +++ b/mono/DBusType/ObjectPath.cs @@ -28,8 +28,10 @@ namespace DBus.DBusType public ObjectPath(IntPtr iter, Service service) { - - this.path = Marshal.PtrToStringAnsi(dbus_message_iter_get_object_path(iter)); + IntPtr raw_str = dbus_message_iter_get_object_path (iter); + this.path = Marshal.PtrToStringAnsi (raw_str); + dbus_free (raw_str); + this.service = service; } @@ -47,7 +49,12 @@ namespace DBus.DBusType public void Append(IntPtr iter) { - if (!dbus_message_iter_append_object_path(iter, Marshal.StringToHGlobalAnsi(Path))) + IntPtr raw_str = Marshal.StringToHGlobalAnsi (Path); + + bool success = dbus_message_iter_append_object_path (iter, raw_str); + Marshal.FreeHGlobal (raw_str); + + if (!success) throw new ApplicationException("Failed to append OBJECT_PATH argument:" + val); } @@ -95,5 +102,8 @@ namespace DBus.DBusType [DllImport("dbus-1")] private extern static bool dbus_message_iter_append_object_path(IntPtr iter, IntPtr path); + + [DllImport("dbus-1")] + private extern static void dbus_free (IntPtr raw); } } diff --git a/mono/DBusType/String.cs b/mono/DBusType/String.cs index bced310a..9d7502fa 100644 --- a/mono/DBusType/String.cs +++ b/mono/DBusType/String.cs @@ -25,12 +25,19 @@ namespace DBus.DBusType public String(IntPtr iter, Service service) { - this.val = Marshal.PtrToStringAnsi(dbus_message_iter_get_string(iter)); + IntPtr raw_str = dbus_message_iter_get_string (iter); + this.val = Marshal.PtrToStringAnsi (raw_str); + dbus_free (raw_str); } public void Append(IntPtr iter) { - if (!dbus_message_iter_append_string(iter, Marshal.StringToHGlobalAnsi(val))) + IntPtr raw_str = Marshal.StringToHGlobalAnsi (val); + + bool success = dbus_message_iter_append_string (iter, raw_str); + Marshal.FreeHGlobal (raw_str); + + if (!success) throw new ApplicationException("Failed to append STRING argument:" + val); } @@ -82,5 +89,8 @@ namespace DBus.DBusType [DllImport("dbus-1")] private extern static bool dbus_message_iter_append_string(IntPtr iter, IntPtr value); + + [DllImport("dbus-1")] + private extern static void dbus_free (IntPtr raw); } } |