Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/coreclr/System.Private.CoreLib/src/System/StubHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1265,9 +1265,18 @@ private unsafe IntPtr ConvertLayoutToNative(object pManagedHome, int dwFlags)
IntPtr pNativeHome = Marshal.AllocCoTaskMem(allocSize);

// marshal the object as class with layout (UnmanagedType.LPStruct)
if (IsIn(dwFlags))
try
{
if (IsIn(dwFlags))
{
StubHelpers.LayoutTypeConvertToUnmanaged(pManagedHome, (byte*)pNativeHome, ref cleanupWorkList);
}
}
catch
{
Comment thread
jkoritzinsky marked this conversation as resolved.
StubHelpers.LayoutTypeConvertToUnmanaged(pManagedHome, (byte*)pNativeHome, ref cleanupWorkList);
StubHelpers.DestroyCleanupList(ref cleanupWorkList);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the full clean-up always safe here? I'd assume that there are already clean-up places for this. The FreeCoTaskMem makes sense, but do we really need the StubHelpers.DestroyCleanupList() as well?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't technically "need" the cleanup list cleanup as the only entries (SafeHandle instances) will eventually be finalized, but without this, they'd have a mismatched refcount until finalization.

Marshal.FreeCoTaskMem(pNativeHome);
throw;
}
if (IsOut(dwFlags))
{
Expand Down
Loading