dbus/mono/DBusType ObjectPath.cs,1.5,1.5.2.1 String.cs,1.3,1.3.2.1

Joe Shaw joe at freedesktop.org
Tue Mar 8 12:42:23 PST 2005


Update of /cvs/dbus/dbus/mono/DBusType
In directory gabe:/tmp/cvs-serv30080/mono/DBusType

Modified Files:
      Tag: dbus-0-23
	ObjectPath.cs String.cs 
Log Message:
2005-03-08  Joe Shaw  <joeshaw at 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.

Index: ObjectPath.cs
===================================================================
RCS file: /cvs/dbus/dbus/mono/DBusType/ObjectPath.cs,v
retrieving revision 1.5
retrieving revision 1.5.2.1
diff -u -d -r1.5 -r1.5.2.1
--- ObjectPath.cs	29 Aug 2004 18:14:30 -0000	1.5
+++ ObjectPath.cs	8 Mar 2005 20:42:21 -0000	1.5.2.1
@@ -28,8 +28,10 @@
     
     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 @@
 
     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 @@
  
     [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);
   }
 }

Index: String.cs
===================================================================
RCS file: /cvs/dbus/dbus/mono/DBusType/String.cs,v
retrieving revision 1.3
retrieving revision 1.3.2.1
diff -u -d -r1.3 -r1.3.2.1
--- String.cs	29 Aug 2004 18:14:30 -0000	1.3
+++ String.cs	8 Mar 2005 20:42:21 -0000	1.3.2.1
@@ -25,12 +25,19 @@
     
     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 @@
  
     [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);
   }
 }



More information about the dbus-commit mailing list