Skip to content

Commit

Permalink
2007-07-26 Jonathan Chambers <joncham@gmail.com>
Browse files Browse the repository at this point in the history
        * ComInteropProxy.cs: Call Marshal.Release after Marshal.QI
        since it AddRef's the object. Fixes COM leak. Also fix eol-style.


svn path=/branches/mono-1-2-5/mcs/; revision=83444
  • Loading branch information
joncham committed Aug 3, 2007
1 parent 4ca325a commit 4b79231
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
5 changes: 5 additions & 0 deletions mcs/class/corlib/Mono.Interop/ChangeLog
@@ -1,3 +1,8 @@
2007-07-26 Jonathan Chambers <joncham@gmail.com>

* ComInteropProxy.cs: Call Marshal.Release after Marshal.QI
since it AddRef's the object. Fixes COM leak. Also fix eol-style.

2007-05-25 Jonathan Chambers <joncham@gmail.com>

* ComInteropProxy.cs: Call __ComObject.GetInterface overload
Expand Down
28 changes: 15 additions & 13 deletions mcs/class/corlib/Mono.Interop/ComInteropProxy.cs
Expand Up @@ -42,16 +42,16 @@ namespace Mono.Interop
{
internal class ComInteropProxy : RealProxy, IRemotingTypeInfo
{
#region Sync with object-internals.h
private __ComObject com_object;
#region Sync with object-internals.h
private __ComObject com_object;
int ref_count = 1; // wrapper ref count
#endregion
private string type_name;

[MethodImplAttribute (MethodImplOptions.InternalCall)]
private extern static void AddProxy (IntPtr pItf, ComInteropProxy proxy);

[MethodImplAttribute (MethodImplOptions.InternalCall)]
private string type_name;

[MethodImplAttribute (MethodImplOptions.InternalCall)]
private extern static void AddProxy (IntPtr pItf, ComInteropProxy proxy);

[MethodImplAttribute (MethodImplOptions.InternalCall)]
internal extern static ComInteropProxy FindProxy (IntPtr pItf);

public ComInteropProxy (Type t)
Expand All @@ -65,7 +65,7 @@ public ComInteropProxy (Type t)
internal void CacheProxy ()
{
// called from unmanaged code after .ctor is invoked
// we need .ctor to create unmanaged object and thus IUnknown property value
// we need .ctor to create unmanaged object and thus IUnknown property value
AddProxy (com_object.IUnknown, this);
}

Expand All @@ -77,7 +77,7 @@ internal ComInteropProxy (IntPtr pUnk)
internal ComInteropProxy (IntPtr pUnk, Type t)
: base (t)
{
com_object = new __ComObject (pUnk);
com_object = new __ComObject (pUnk);
CacheProxy ();
}

Expand All @@ -86,13 +86,15 @@ internal static ComInteropProxy GetProxy (IntPtr pItf, Type t)
IntPtr ppv;
Guid iid = __ComObject.IID_IUnknown;
int hr = Marshal.QueryInterface (pItf, ref iid, out ppv);
Marshal.ThrowExceptionForHR (hr);
Marshal.ThrowExceptionForHR (hr);
ComInteropProxy obj = FindProxy (ppv);
if (obj == null) {
Marshal.Release (pItf);
return new ComInteropProxy (ppv);
}
else {
System.Threading.Interlocked.Increment (ref obj.ref_count);
else {
Marshal.Release (pItf);
System.Threading.Interlocked.Increment (ref obj.ref_count);
return obj;
}
}
Expand Down

0 comments on commit 4b79231

Please sign in to comment.