From 5cc18edbf7ac2b1a833dc5da60d2a8bde742cb66 Mon Sep 17 00:00:00 2001 From: Songstats Audit Date: Sat, 29 Aug 2026 22:20:15 +0200 Subject: [PATCH] Close duplex pipe when process launch fails --- lib/childprocess/process_spawn_process.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/childprocess/process_spawn_process.rb b/lib/childprocess/process_spawn_process.rb index 11bd3a6..f1b22c6 100644 --- a/lib/childprocess/process_spawn_process.rb +++ b/lib/childprocess/process_spawn_process.rb @@ -54,6 +54,7 @@ def launch_process options[:out] = io.stdout ? io.stdout.fileno : File::NULL options[:err] = io.stderr ? io.stderr.fileno : File::NULL + reader = writer = nil if duplex? reader, writer = ::IO.pipe options[:in] = reader.fileno @@ -86,6 +87,11 @@ def launch_process @pid = ::Process.spawn(environment, *args, options) rescue SystemCallError => e raise LaunchError, e.message + ensure + unless @pid + reader&.close + writer&.close + end end if duplex?