From d5baa14e684167fabdd980ee16d307994398f912 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 22 Oct 2024 10:36:47 -0700 Subject: [PATCH] [release/9.0] Initialize managed and native values in the ICustomMarshaler marshaler to null when the other is null. (#109096) * Initialize managed and native values to null when the other is null. * Update StubHelpers.cs --------- Co-authored-by: Jeremy Koritzinsky Co-authored-by: Jeremy Koritzinsky --- src/coreclr/System.Private.CoreLib/src/System/StubHelpers.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/coreclr/System.Private.CoreLib/src/System/StubHelpers.cs b/src/coreclr/System.Private.CoreLib/src/System/StubHelpers.cs index 4d04557565c3c..2d379d4326c88 100644 --- a/src/coreclr/System.Private.CoreLib/src/System/StubHelpers.cs +++ b/src/coreclr/System.Private.CoreLib/src/System/StubHelpers.cs @@ -807,17 +807,19 @@ internal static unsafe void ConvertContentsToNative(ICustomMarshaler marshaler, // COMPAT: We never pass null to MarshalManagedToNative. if (pManagedHome is null) { + *pNativeHome = IntPtr.Zero; return; } *pNativeHome = marshaler.MarshalManagedToNative(pManagedHome); } - internal static void ConvertContentsToManaged(ICustomMarshaler marshaler, ref object pManagedHome, IntPtr* pNativeHome) + internal static void ConvertContentsToManaged(ICustomMarshaler marshaler, ref object? pManagedHome, IntPtr* pNativeHome) { // COMPAT: We never pass null to MarshalNativeToManaged. if (*pNativeHome == IntPtr.Zero) { + pManagedHome = null; return; }