Skip to content

Release resources that could call callbacks before returning from HcsVirtualMachine's constructor on failure - #41908

Merged
Blue (OneBlue) merged 1 commit into
masterfrom
user/oneblue/fix-race-8
Oct 13, 2026
Merged

Blue (OneBlue) merged 1 commit into
masterfrom
user/oneblue/fix-race-8

Conversation

@OneBlue

Copy link
Copy Markdown
Collaborator

Summary of the Pull Request

This change solves a potential crash if HcsVirtualMachine throws an exception. If that happens, its destructor won't run, and its field will be destroyed in reverse-order. That can cause a use-after-free in callbacks from the guest device manager or compute system are being called.

PR Checklist

  • Closes: Link to issue #xxx
  • Communication: I've discussed this with core contributors already. If work hasn't been agreed, this work might be rejected
  • Tests: Added/updated if needed and all pass
  • Localization: All end user facing strings can be localized
  • Dev docs: Added/updated if needed
  • Documentation updated: If checked, please file a pull request on our docs repo and link it here: #xxx

Detailed Description of the Pull Request / Additional comments

Validation Steps Performed

@OneBlue
Blue (OneBlue) requested a review from a team as a code owner October 13, 2026 18:55
Copilot AI balanced review requested due to automatic review settings October 13, 2026 18:55

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

The cleanup preserves required teardown ordering and releases the lock before draining callbacks.

0 open findings

What changed in this PR

Prevents use-after-free during HcsVirtualMachine constructor failure by draining callback-producing resources before member destruction.

Changes:

  • Uses an unlockable constructor lock.
  • Adds failure-only cleanup for device-manager and HCS callbacks.
File Description
src/​windows/​service/​exe/​HcsVirtualMachine.cpp Safely drains callbacks during failed construction.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@OneBlue
Blue (OneBlue) merged commit df33abb into master Oct 13, 2026
12 checks passed
@OneBlue
Blue (OneBlue) deleted the user/oneblue/fix-race-8 branch October 13, 2026 21:57
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