Close isExecutable command outpipe file handle after use
authorClaudio Cambra <claudio.cambra@nextcloud.com>
Thu, 28 Nov 2024 16:55:35 +0000 (00:55 +0800)
committerbackportbot[bot] <backportbot[bot]@users.noreply.github.com>
Tue, 10 Dec 2024 08:26:34 +0000 (08:26 +0000)
Prevents exhaustion of fds

Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
admin/osx/mac-crafter/Sources/Utils/Codesign.swift

index b511f0a443e27750a143c4107564e3aba0e54050..f262ff39d7bacb7140c17a322ea83ee9b59e4444 100644 (file)
@@ -45,7 +45,9 @@ func isExecutable(_ path: String) throws -> Bool {
         throw CodeSigningError.failedToCodeSign("Failed to determine if \(path) is an executable.")
     }
 
-    let outputData = outPipe.fileHandleForReading.readDataToEndOfFile()
+    let outputFileHandle = outPipe.fileHandleForReading
+    let outputData = outputFileHandle.readDataToEndOfFile()
+    try outputFileHandle.close()
     let output = String(data: outputData, encoding: .utf8) ?? ""
     return output.contains("Mach-O 64-bit executable")
 }