-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Fix for incorrect release of CCW holder #84927
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
Fixes: microsoft/CsWinRT#1321 Make ComWrappers in C# work closely with how C++ part works - `RefCount` => `curr` is plain typo - Do not destroy wrappers if ref count == 0. That's mimic how CoreCLR work - Also discover 2 tests which are plainly wrong, since they do not work under CoreCLR
|
/cc @dotnet/interop-contrib |
| { | ||
| ManagedObjectWrapper* wrapper = ComInterfaceDispatch.ToManagedObjectWrapper((ComInterfaceDispatch*)pThis); | ||
| uint refcount = wrapper->Release(); | ||
| if (wrapper->RefCount == 0) |
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.
Released actually here
Lines 282 to 287 in e21242a
| ~ManagedObjectWrapperHolder() | |
| { | |
| // Release GC handle created when MOW was built. | |
| _wrapper->Destroy(); | |
| NativeMemory.Free(_wrapper); | |
| } |
|
LGTM other than what looks like some remains of the dead code in the smoke test. |
|
Would this meet the bar for a .NET 7 servicing release, or will this be .NET 8 only? |
jkoritzinsky
left a comment
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.
After looking into this more, there's a more serious issue here that needs to be fixed before this is merged in. The ComWrappers implementation on NativeAOT uses a strong GC handle to hold the managed object alive from the MOW. With this change, the managed object will never be released, as the MOW will hold a strong ref to the managed object that will not be released until the MOW is destroyed, which won't happen until after the managed object is released since the MOW is kept alive by the managed object through a ConditionalWeakTable.
I believe we need to change the ComWrappers implementation to use ref-counted handles in this case. NativeAOT has partial support for ref-counted handles, but it might need to be extended slightly to work as well as possible.
Fixes: microsoft/CsWinRT#1321 Make ComWrappers in C# work closely with how C++ part works
RefCount=>curris plain typo