Skip to content

Conversation

@jkoritzinsky
Copy link
Member

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.

… poniter to the managed field with a null pointer instead of skipping the ClearNative call.
@jkotas
Copy link
Member

jkotas commented Oct 6, 2023

Can we write a test for this?

@jkoritzinsky
Copy link
Member Author

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.
@jkoritzinsky
Copy link
Member Author

@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 ICustomMarshaler doesn't work as we disallow ICustomMarshaler marshalling on fields.

@AaronRobinsonMSFT
Copy link
Member

@jkoritzinsky Can you also please run this test a dozen times or so on a Checked build with DOTNET_GCStress=C?

@jkoritzinsky
Copy link
Member Author

Validated that the test passes with GCStress=C.

…we are testing and how we are testing it as it is very much not straightfoward.
@jkoritzinsky jkoritzinsky merged commit 2051451 into dotnet:main Oct 10, 2023
@ghost ghost locked as resolved and limited conversation to collaborators Nov 9, 2023
@jkoritzinsky jkoritzinsky deleted the struct-free branch March 22, 2024 01:24
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants