Skip to content

Commit 6ab0f24

Browse files
authored
Make the code that deals with the remaining plugin output data more robust (#5818)
This code in DefaultPluginScriptRunner uses NSFileHandle's `readabilityHandler`, and there were some circumstances in which this code could crash. This change introduces local variables that keep both the handle and the handler alive long enough to not crash rather than doing it all in one expression. Note that this isn't a race condition — the handler does the correct locking. But the object lifetime was a bit ambiguous with the existing line of code, and the new one removes the ambiguity. No new unit tests — 21 of the existing unit tests cover this, and that's how the ambiguity was found. rdar://101229820
1 parent e5266bf commit 6ab0f24

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

Sources/Workspace/DefaultPluginScriptRunner.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,10 @@ public struct DefaultPluginScriptRunner: PluginScriptRunner, Cancellable {
516516
}
517517

518518
// Read and pass on any remaining messages from the plugin.
519-
stdoutPipe.fileHandleForReading.readabilityHandler?(stdoutPipe.fileHandleForReading)
519+
let handle = stdoutPipe.fileHandleForReading
520+
if let handler = handle.readabilityHandler {
521+
handler(handle)
522+
}
520523

521524
// Call the completion block with a result that depends on how the process ended.
522525
callbackQueue.async {

0 commit comments

Comments
 (0)