Fix double COM release of SOS debugger services - #6080
Merged
max-charlamb merged 1 commit intoOct 1, 2026
Merged
Conversation
Let the global service container dispose DebuggerServices once instead of explicitly releasing its COM reference again. Detach diagnostic logging before disposal so trace output cannot call through the released debugger interface. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 13f45840-6112-4dc4-ab2f-c020bd189022
steveisok
approved these changes
Sep 30, 2026
max-charlamb
enabled auto-merge (squash)
October 1, 2026 16:12
Member
Author
|
/ba-g unrelated transient symbol server test flake |
This was referenced Oct 3, 2026
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.
Problem
HostServices.Uninitializereleases the native debugger-services COM reference twice:DebuggerServicesis registered in the global service container asSOSHost.INativeDebugger. Although that interface does not inheritIDisposable, the concrete object inheritsCallableCOMWrapper, which does.ServiceContainer.DisposeServices()checks the concrete instances forIDisposableand callsDebuggerServices.Dispose(), releasing the wrapper's owned COM reference.Uninitializethen callsDebuggerServices.ReleaseWithCheck(), which invokes a raw COMRelease()again rather than respecting the wrapper's disposed state.This is a double COM release, not necessarily an immediate double free in every run. With other references outstanding, it incorrectly consumes another owner's reference; if the first release destroys the native object, the second release can call through freed memory.
Provenance
The explicit release predates service-container ownership and was originally appropriate. #3448 introduced global service disposal while leaving
DebuggerServicesoutside the container. #4285 subsequently registered the same wrapper asSOSHost.INativeClientsoSOSHostcould use the existing native debugger client, but retained the manual release. #4437 later renamed that interface toINativeDebugger.CallableCOMWrapperalready implementedIDisposablewhen the registration was added, so this is an ownership mismatch rather than a recent ClrMD disposal-contract change.Fix
DebuggerServicesexactly once.DiagnosticLoggingServicefrom its debugger-backed console before disposing global services. Its singleton retains aConsoleServiceFromDebuggerServicesthat forwards trace output to the native debugger interface; leaving that connection active during disposal could issue output through a released pointer.This was found while investigating Windows ARM64 SOS tests in #6075, but the ownership bug is architecture-independent. This PR does not establish that it caused the separate
OutputversusOutput2callback behavior.Validation
Targeted restore and build of
src\SOS\SOS.Extensions\SOS.Extensions.csprojsucceeded fornet8.0andnet462with zero warnings and errors. No native teardown reproduction or ARM64 runtime validation has been performed for this fix.