Skip to content
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

Merged

Conversation

jkoritzinsky
Copy link
Member

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.

…n array of structs of types that use old-style managed marshalers
@jkoritzinsky jkoritzinsky added Servicing-consider Issue for next servicing release review area-Interop-coreclr labels Oct 6, 2023
@jkoritzinsky jkoritzinsky added this to the 6.0.x milestone Oct 6, 2023
@ghost ghost assigned jkoritzinsky Oct 6, 2023
@jkoritzinsky
Copy link
Member Author

/backport to release/7.0-staging

@jkoritzinsky
Copy link
Member Author

/backport to release/8.0

@github-actions
Copy link
Contributor

github-actions bot commented Oct 6, 2023

Started backporting to release/7.0-staging: https://github.com/dotnet/runtime/actions/runs/6435796905

@github-actions
Copy link
Contributor

github-actions bot commented Oct 6, 2023

Started backporting to release/8.0: https://github.com/dotnet/runtime/actions/runs/6435797694

Copy link
Member

@jeffschwMSFT jeffschwMSFT left a 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

@jeffschwMSFT jeffschwMSFT added Servicing-approved Approved for servicing release and removed Servicing-consider Issue for next servicing release review labels Oct 9, 2023
@jkoritzinsky
Copy link
Member Author

/backport to release/7.0-staging

@jkoritzinsky
Copy link
Member Author

/backport to release/8.0

@github-actions
Copy link
Contributor

github-actions bot commented Oct 9, 2023

Started backporting to release/7.0-staging: https://github.com/dotnet/runtime/actions/runs/6460257377

@github-actions
Copy link
Contributor

github-actions bot commented Oct 9, 2023

Started backporting to release/8.0: https://github.com/dotnet/runtime/actions/runs/6460258950

@jkoritzinsky
Copy link
Member Author

Failures are unrelated (also showing up in release/6.0-staging without this change).

@jkoritzinsky jkoritzinsky merged commit 4f5047f into dotnet:release/6.0-staging Oct 9, 2023
98 of 101 checks passed
@AmeerAssi
Copy link

@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?
or do you know when it is planned to be released?

@ghost ghost locked as resolved and limited conversation to collaborators Nov 30, 2023
@jkoritzinsky jkoritzinsky deleted the 6.0-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.
Labels
area-Interop-coreclr Servicing-approved Approved for servicing release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants