From d6b34cec930a8e95bbcb616911e105990a57648b Mon Sep 17 00:00:00 2001 From: Casey Date: Tue, 5 May 2026 23:18:36 +0200 Subject: [PATCH 1/2] fix: 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]! - Line 126: Iterate entries.values instead of force-unwrapping by key --- Services/UTMRegistry.swift | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Services/UTMRegistry.swift b/Services/UTMRegistry.swift index 1b5e695179..508fdbf345 100644 --- a/Services/UTMRegistry.swift +++ b/Services/UTMRegistry.swift @@ -37,8 +37,9 @@ class UTMRegistry: NSObject { @Published private var entries: [String: UTMRegistryEntry] { didSet { let toAdd = entries.keys.filter({ !changeListeners.keys.contains($0) }) - for key in toAdd { - let entry = entries[key]! + .compactMap { entries[$0] } + for entry in toAdd { + let key = entry.uuid.uuidString changeListeners[key] = entry.objectWillChange .debounce(for: .seconds(1), scheduler: DispatchQueue.global(qos: .utility)) .sink { [weak self, weak entry] in @@ -122,8 +123,7 @@ class UTMRegistry: NSObject { /// - Parameter entries: All entries to commit private func commitAll(entries: [String: UTMRegistryEntry]) { var newSerializedEntries: [String: Any] = [:] - for key in entries.keys { - let entry = entries[key]! + for entry in entries.values { commit(entry: entry, to: &newSerializedEntries) } serializedEntries = newSerializedEntries From b2f4ae322ddeb7265e73ce897db1353da65bbe9d Mon Sep 17 00:00:00 2001 From: Casey Date: Wed, 6 May 2026 17:21:09 +0200 Subject: [PATCH 2/2] fix: 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. --- Services/UTMAppleVirtualMachine.swift | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Services/UTMAppleVirtualMachine.swift b/Services/UTMAppleVirtualMachine.swift index 4917dc81a9..89d24688a2 100644 --- a/Services/UTMAppleVirtualMachine.swift +++ b/Services/UTMAppleVirtualMachine.swift @@ -582,6 +582,8 @@ final class UTMAppleVirtualMachine: UTMVirtualMachine { throw UTMAppleVirtualMachineError.operatingSystemInstallNotSupported #endif } catch { + progressObserver = nil + installProgress = nil await stopAccesingResources() delegate?.virtualMachine(self, didCompleteInstallation: false) state = .stopped