Fix CLR->COM RCW ownership tracking on the slow path#126731
Open
AaronRobinsonMSFT wants to merge 2 commits intodotnet:mainfrom
Open
Fix CLR->COM RCW ownership tracking on the slow path#126731AaronRobinsonMSFT wants to merge 2 commits intodotnet:mainfrom
AaronRobinsonMSFT wants to merge 2 commits intodotnet:mainfrom
Conversation
Have the slow GetCOMIPFromRCW helper report whether the returned interface pointer actually requires cleanup, so RCW cache hits after OLE TLS initialization are not released as if they were freshly acquired.\n\nFixes dotnet#126619\n\nCo-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
|
Tagging subscribers to this area: @agocke |
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes CLR→COM stub cleanup ownership tracking when StubHelpers.GetCOMIPFromRCW() falls back to the slow path on native-created threads, preventing erroneous Release calls for RCW-cache hits after OLE TLS initialization (issue #126619).
Changes:
- Extend the QCall slow helper (
StubHelpers_GetCOMIPFromRCWSlow) to return an explicitpfNeedsReleaseflag. - Update the slow helper implementation to set
pfNeedsRelease=trueonly for freshly acquired COM IPs (and keep it false for RCW-cache hits). - Update managed
StubHelpers.GetCOMIPFromRCWto delegatepfNeedsReleasedetermination to the slow path.
Show a summary per file
| File | Description |
|---|---|
| src/coreclr/vm/stubhelpers.h | Updates the slow-path QCall signature to include an explicit ownership/cleanup flag. |
| src/coreclr/vm/stubhelpers.cpp | Implements ownership tracking: cache hits return borrowed pointers (no release), fresh acquisitions require release. |
| src/coreclr/System.Private.CoreLib/src/System/StubHelpers.cs | Plumbs pfNeedsRelease through the slow path so cleanup behavior matches actual pointer ownership. |
Copilot's findings
- Files reviewed: 3/3 changed files
- Comments generated: 1
jkoritzinsky
approved these changes
Apr 9, 2026
Extend TrackMyLifetimeTesting with a simple Method() call and add a native-thread callback test that exercises the agile RCW path covered by dotnet#126619. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Member
Author
|
@elinor-fung @jkoritzinsky I've added a test here. It was a bit complicated and I wasted about an hour trying to reason why other tests were failing. Apparently Copilot missed the semantic meaning of |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #126619.
This was a regression introduced in #114609
When
System.StubHelpers.GetCOMIPFromRCW()misses the fast path on a native-created thread, the slow path can create OLE TLS and still resolve the COM interface pointer from the RCW cache. Those cache hits are borrowed and should not be released by the stub cleanup path.This change moves the
pfNeedsReleasedecision to the slow helper so it can distinguish between:ComObject::GetComIPFromRCWThrowingTesting: