Skip to content

Fix COM ref counting in SOSMethodEnum simulator#5746

Merged
hoyosjs merged 1 commit intodotnet:mainfrom
max-charlamb:com-ref-counting-fix
Mar 5, 2026
Merged

Fix COM ref counting in SOSMethodEnum simulator#5746
hoyosjs merged 1 commit intodotnet:mainfrom
max-charlamb:com-ref-counting-fix

Conversation

@max-charlamb
Copy link
Member

@max-charlamb max-charlamb commented Mar 5, 2026

Summary

Matching PR for dotnet/runtime#125231, which fixes DefaultCOMImpl::Release() reference counting bugs in the DAC.

Changes

1. Fix SOSMethodEnum simulator COM ref counting (util.cpp)

The SOSDacInterface15 simulator's GetMethodTableSlotEnumerator had the same bug pattern fixed in the runtime PR — raw pointer assignment without QueryInterface, and the null check occurred after the dereference. Fixed to:

  • Initialize refCount to 0 (matching DefaultCOMImpl convention)
  • Use QueryInterface to return the interface, properly calling AddRef
  • Check for null before dereferencing the out parameter
  • Use delete on failure (since QueryInterface wasn't called at refCount 0)

2. Fix ISOSMethodEnum leak in strike.cpp

Changed raw ISOSMethodEnum* to ToRelease<ISOSMethodEnum> so Release() is called when the pointer goes out of scope, matching the pattern used everywhere else (e.g., ToRelease<ISOSHandleEnum>).

@max-charlamb max-charlamb requested a review from a team as a code owner March 5, 2026 18:24
Copilot AI review requested due to automatic review settings March 5, 2026 18:24
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@max-charlamb max-charlamb force-pushed the com-ref-counting-fix branch from c439149 to 65effde Compare March 5, 2026 19:37
@max-charlamb max-charlamb changed the title Fix COM ref counting in SOSMethodEnum simulator and bump SOS_BREAKING_CHANGE_VERSION Fix COM ref counting in SOSMethodEnum simulator Mar 5, 2026
@max-charlamb max-charlamb force-pushed the com-ref-counting-fix branch from 65effde to 7f23d51 Compare March 5, 2026 19:42
@max-charlamb max-charlamb changed the title Fix COM ref counting in SOSMethodEnum simulator Fix COM ref counting in SOSMethodEnum simulator and bump SOS_BREAKING_CHANGE_VERSION Mar 5, 2026
…_CHANGE_VERSION

- Bump SOS_BREAKING_CHANGE_VERSION from 5 to 6 to match runtime.
- Fix SOSMethodEnum simulator to use standard COM ref counting:
  initialize refCount to 0 and use QueryInterface to return the
  interface pointer with a proper AddRef.
- Fix ISOSMethodEnum leak in DumpMT by using ToRelease<>.

Matching PR: dotnet/runtime#125231

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@max-charlamb max-charlamb force-pushed the com-ref-counting-fix branch from 7f23d51 to 0f3b0c8 Compare March 5, 2026 21:44
@hoyosjs
Copy link
Member

hoyosjs commented Mar 5, 2026

Do we need any extra release for breaking version less than 6?

This change doesn't change behavior at all. It would be nice to reclaim resources but we haven't gotten reports.

@hoyosjs hoyosjs merged commit 14d299f into dotnet:main Mar 5, 2026
16 of 18 checks passed
@max-charlamb max-charlamb changed the title Fix COM ref counting in SOSMethodEnum simulator and bump SOS_BREAKING_CHANGE_VERSION Fix COM ref counting in SOSMethodEnum simulator Mar 6, 2026
max-charlamb added a commit that referenced this pull request Mar 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants