Skip to content

fix: prevent crash from force unwrap in UTMRegistry and memory leak in UTMAppleVirtualMachine#7701

Open
caseydapro2020 wants to merge 2 commits intoutmapp:mainfrom
caseydapro2020:fix/registry-force-unwrap
Open

fix: prevent crash from force unwrap in UTMRegistry and memory leak in UTMAppleVirtualMachine#7701
caseydapro2020 wants to merge 2 commits intoutmapp:mainfrom
caseydapro2020:fix/registry-force-unwrap

Conversation

@caseydapro2020
Copy link
Copy Markdown

@caseydapro2020 caseydapro2020 commented May 5, 2026

Fix 1: Prevent crash from force unwrap in UTMRegistry

Replace unsafe force unwraps with compactMap and direct value iteration to prevent crashes during concurrent registry access.

  • Line 41: Use compactMap instead of entries[key]! in the didSet observer
  • Line 126: Iterate entries.values instead of force-unwrapping by key in commitAll()

This prevents potential crashes when registry entries are modified concurrently during debounce callbacks, which could occur when users rapidly create/delete VMs.

Fix 2: Memory leak in UTMAppleVirtualMachine when installation fails

Clear progressObserver and installProgress in the error path of installVM() to break the retain cycle caused by the KVO observation closure capturing self strongly.

Without this fix, failed macOS installations cause the VM instance to be retained in memory until the next successful installation or app termination.

Testing

Both fixes were verified by successful builds.

Casey added 2 commits May 5, 2026 23:18
Replace unsafe force unwraps with compactMap and direct value iteration
to prevent crashes during concurrent registry access.

- Line 41: Use compactMap instead of entries[key]!
- Line 126: Iterate entries.values instead of force-unwrapping by key
Clear progressObserver and installProgress in the error path of
installVM() to break the retain cycle caused by the KVO observation
closure capturing self strongly.
@caseydapro2020 caseydapro2020 changed the title fix: prevent crash from force unwrap in UTMRegistry fix: prevent crash from force unwrap in UTMRegistry and memory leak in UTMAppleVirtualMachine May 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.

1 participant