Skip to content

Commit

Permalink
Fix EnumerableViewOfDispatch.GetEnumerator ref counting (dotnet#34230)
Browse files Browse the repository at this point in the history
  • Loading branch information
elinor-fung authored Mar 30, 2020
1 parent 8511b5b commit b95caba
Showing 1 changed file with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,25 @@ public IEnumerator GetEnumerator()
IntPtr.Zero);
}

object? resultAsObject = result.ToObject();
if (!(resultAsObject is IEnumVARIANT enumVariant))
IntPtr enumVariantPtr = IntPtr.Zero;
try
{
throw new InvalidOperationException(SR.InvalidOp_InvalidNewEnumVariant);
object? resultAsObject = result.ToObject();
if (!(resultAsObject is IEnumVARIANT enumVariant))
{
throw new InvalidOperationException(SR.InvalidOp_InvalidNewEnumVariant);
}

enumVariantPtr = Marshal.GetIUnknownForObject(enumVariant);
return (IEnumerator)EnumeratorToEnumVariantMarshaler.GetInstance(null).MarshalNativeToManaged(enumVariantPtr);
}
finally
{
result.Clear();

return (IEnumerator)EnumeratorToEnumVariantMarshaler.GetInstance(null).MarshalNativeToManaged(Marshal.GetIUnknownForObject(enumVariant));
if (enumVariantPtr != IntPtr.Zero)
Marshal.Release(enumVariantPtr);
}
}

public object GetUnderlyingObject()
Expand Down

0 comments on commit b95caba

Please sign in to comment.