-
Couldn't load subscription status.
- Fork 5.2k
Fix a memory leak in runtime interop stubs when using an array of structs of types that use old-style managed marshalers #93089
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
… poniter to the managed field with a null pointer instead of skipping the ClearNative call.
|
Can we write a test for this? |
|
I have an idea for one. I'll try it out tomorrow. |
…ate lifetimes. We can't use ICustomMarshaler here as that isn't supported in field scenarios.
|
@jkotas I've constructed a test using the "Fixed Array" marshaller with a COM object to give me a testable lifetime hook. Sadly my initial idea of using |
src/tests/Interop/ArrayMarshalling/StructArray/MarshalStructArrayTest.cs
Outdated
Show resolved
Hide resolved
src/tests/Interop/ArrayMarshalling/StructArray/MarshalStructArrayTest.cs
Outdated
Show resolved
Hide resolved
src/tests/Interop/ArrayMarshalling/StructArray/MarshalStructArrayTest.cs
Outdated
Show resolved
Hide resolved
|
@jkoritzinsky Can you also please run this test a dozen times or so on a Checked build with |
…rayTest.cs Co-authored-by: Aaron Robinson <[email protected]>
|
Validated that the test passes with GCStress=C. |
src/tests/Interop/ArrayMarshalling/StructArray/MarshalStructArrayTest.cs
Show resolved
Hide resolved
src/tests/Interop/ArrayMarshalling/StructArray/MarshalStructArrayTest.cs
Outdated
Show resolved
Hide resolved
src/tests/Interop/ArrayMarshalling/StructArray/MarshalStructArrayNative.cpp
Outdated
Show resolved
Hide resolved
…we are testing and how we are testing it as it is very much not straightfoward.
When we don't have a managed value in a ClearNative call, the managed pointer to the managed field with a null pointer instead of skipping the ClearNative call.
The initial approach was taken in dotnet/coreclr#27562 to avoid bad GC pointers, but this approach also avoids bad GC pointers and correctly frees the memory.
Validated locally. I'm also going to validate offline with a 1st-party customer that reported this issue and then backport to 6.0-8.0.