You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In AsAnyMarshaler.LayoutImplementation.ConvertToNative (src/coreclr/System.Private.CoreLib/src/System/StubHelpers.cs), native memory allocated via Marshal.AllocCoTaskMem is not freed if LayoutTypeConvertToUnmanaged throws an exception.
If LayoutTypeConvertToUnmanaged throws, pNative is leaked. The fix should wrap the conversion in a try/catch that frees pNative on failure, similar to the pattern used by ArrayImplementation.ConvertToNative in the same file:
This issue was filed based on a code review finding by GitHub Copilot. This is a pre-existing issue in the AsAnyMarshaler code, not a regression from recent changes.
Description
In
AsAnyMarshaler.LayoutImplementation.ConvertToNative(src/coreclr/System.Private.CoreLib/src/System/StubHelpers.cs), native memory allocated viaMarshal.AllocCoTaskMemis not freed ifLayoutTypeConvertToUnmanagedthrows an exception.https://github.com/dotnet/runtime/blob/main/src/coreclr/System.Private.CoreLib/src/System/StubHelpers.cs#L1032-L1040
The current code:
If
LayoutTypeConvertToUnmanagedthrows,pNativeis leaked. The fix should wrap the conversion in a try/catch that freespNativeon failure, similar to the pattern used byArrayImplementation.ConvertToNativein the same file:Note
This issue was filed based on a code review finding by GitHub Copilot. This is a pre-existing issue in the
AsAnyMarshalercode, not a regression from recent changes.Area
area-Interop-coreclr