-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
[release/6.0] Fix a memory leak in runtime interop stubs when using an array of structs of types that use old-style managed marshalers #93147
Conversation
…n array of structs of types that use old-style managed marshalers
/backport to release/7.0-staging |
/backport to release/8.0 |
Started backporting to release/7.0-staging: https://github.com/dotnet/runtime/actions/runs/6435796905 |
Started backporting to release/8.0: https://github.com/dotnet/runtime/actions/runs/6435797694 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
approved. please get a code review. we will take for consideration in 6.0.x
/backport to release/7.0-staging |
/backport to release/8.0 |
Started backporting to release/7.0-staging: https://github.com/dotnet/runtime/actions/runs/6460257377 |
Started backporting to release/8.0: https://github.com/dotnet/runtime/actions/runs/6460258950 |
Failures are unrelated (also showing up in release/6.0-staging without this change). |
4f5047f
into
dotnet:release/6.0-staging
@jkoritzinsky thanks for doing this fix. Can I get a drop of this change to test and see if it fixes the leak I am experiencing? |
Fixes Issue (Issue was reported by a 1st party over email)
main PR #93089
Description
When passing an array of structs that contains an array field marshalled as a SAFEARRAY or "ByValArray" field to a P/Invoke or a COM interop call, the native array and its contents are not released. This PR changes the marshalling logic such that the native array and contents will be released when they should be.
Customer Impact
Customers without this fix that have interop code with this shape will have unmanaged memory leaks.
Regression
This is a regression that was introduced in .NET 5.
Testing
This fix has been manually validated in main and a unit test has been added to the PR in main. This fix has also manually been validated in this branch with the customer and it fixes their scenario.
Risk
The risk for this PR is low. The logic here will only be hit in these two scenarios, and the expected and documented behavior is that we do not leak this memory. It is very unlikely that customers have taken a dependency on this memory being leaked.