Skip to content

Commit

Permalink
scripting: fix missing retain on scripted object
Browse files Browse the repository at this point in the history
Fixes #5963
  • Loading branch information
osy committed Mar 31, 2024
1 parent 412878a commit 2724075
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
15 changes: 6 additions & 9 deletions Scripting/UTMScriptingGuestFileImpl.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,14 @@ import QEMUKitInternal
class UTMScriptingGuestFileImpl: NSObject, UTMScriptable {
@objc private(set) var id: Int

weak private var parent: UTMScriptingVirtualMachineImpl?
private var parent: UTMScriptingVirtualMachineImpl

init(from handle: Int, parent: UTMScriptingVirtualMachineImpl) {
self.id = handle
self.parent = parent
}

override var objectSpecifier: NSScriptObjectSpecifier? {
guard let parent = parent else {
return nil
}
guard let parentDescription = parent.classDescription as? NSScriptClassDescription else {
return nil
}
Expand Down Expand Up @@ -66,7 +63,7 @@ class UTMScriptingGuestFileImpl: NSObject, UTMScriptable {
let isBase64Encoded = command.evaluatedArguments?["isBase64Encoded"] as? Bool ?? false
let isClosing = command.evaluatedArguments?["isClosing"] as? Bool ?? true
withScriptCommand(command) { [self] in
guard let guestAgent = await parent?.guestAgent else {
guard let guestAgent = await parent.guestAgent else {
throw UTMScriptingVirtualMachineImpl.ScriptingError.guestAgentNotRunning
}
defer {
Expand Down Expand Up @@ -96,7 +93,7 @@ class UTMScriptingGuestFileImpl: NSObject, UTMScriptable {
let file = command.evaluatedArguments?["file"] as? URL
let isClosing = command.evaluatedArguments?["isClosing"] as? Bool ?? true
withScriptCommand(command) { [self] in
guard let guestAgent = await parent?.guestAgent else {
guard let guestAgent = await parent.guestAgent else {
throw UTMScriptingVirtualMachineImpl.ScriptingError.guestAgentNotRunning
}
defer {
Expand Down Expand Up @@ -129,7 +126,7 @@ class UTMScriptingGuestFileImpl: NSObject, UTMScriptable {
let isBase64Encoded = command.evaluatedArguments?["isBase64Encoded"] as? Bool ?? false
let isClosing = command.evaluatedArguments?["isClosing"] as? Bool ?? true
withScriptCommand(command) { [self] in
guard let guestAgent = await parent?.guestAgent else {
guard let guestAgent = await parent.guestAgent else {
throw UTMScriptingVirtualMachineImpl.ScriptingError.guestAgentNotRunning
}
defer {
Expand All @@ -153,7 +150,7 @@ class UTMScriptingGuestFileImpl: NSObject, UTMScriptable {
let file = command.evaluatedArguments?["file"] as? URL
let isClosing = command.evaluatedArguments?["isClosing"] as? Bool ?? true
withScriptCommand(command) { [self] in
guard let guestAgent = await parent?.guestAgent else {
guard let guestAgent = await parent.guestAgent else {
throw UTMScriptingVirtualMachineImpl.ScriptingError.guestAgentNotRunning
}
defer {
Expand All @@ -180,7 +177,7 @@ class UTMScriptingGuestFileImpl: NSObject, UTMScriptable {

@objc func close(_ command: NSScriptCommand) {
withScriptCommand(command) { [self] in
guard let guestAgent = await parent?.guestAgent else {
guard let guestAgent = await parent.guestAgent else {
throw UTMScriptingVirtualMachineImpl.ScriptingError.guestAgentNotRunning
}
try await guestAgent.guestFileClose(id)
Expand Down
7 changes: 2 additions & 5 deletions Scripting/UTMScriptingGuestProcessImpl.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,14 @@ import Foundation
class UTMScriptingGuestProcessImpl: NSObject, UTMScriptable {
@objc private(set) var id: Int

weak private var parent: UTMScriptingVirtualMachineImpl?
private var parent: UTMScriptingVirtualMachineImpl

init(from pid: Int, parent: UTMScriptingVirtualMachineImpl) {
self.id = pid
self.parent = parent
}

override var objectSpecifier: NSScriptObjectSpecifier? {
guard let parent = parent else {
return nil
}
guard let parentDescription = parent.classDescription as? NSScriptClassDescription else {
return nil
}
Expand All @@ -44,7 +41,7 @@ class UTMScriptingGuestProcessImpl: NSObject, UTMScriptable {

@objc func getResult(_ command: NSScriptCommand) {
withScriptCommand(command) { [self] in
guard let guestAgent = await parent?.guestAgent else {
guard let guestAgent = await parent.guestAgent else {
throw UTMScriptingVirtualMachineImpl.ScriptingError.guestAgentNotRunning
}
let status = try await guestAgent.guestExecStatus(id)
Expand Down

0 comments on commit 2724075

Please sign in to comment.