From 4de2b1ea65e6b54cedfe56268a8bf8e9446addb0 Mon Sep 17 00:00:00 2001 From: Alex Kladov Date: Thu, 30 Jan 2025 12:01:53 +0000 Subject: [PATCH] std: don't leak a process in Child.run in case of an error Closes: #22433 --- lib/std/process/Child.zig | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/std/process/Child.zig b/lib/std/process/Child.zig index fa824e0aec..2796207496 100644 --- a/lib/std/process/Child.zig +++ b/lib/std/process/Child.zig @@ -428,12 +428,15 @@ pub fn run(args: struct { } try child.spawn(); + errdefer { + _ = child.kill() catch {}; + } try child.collectOutput(&stdout, &stderr, args.max_output_bytes); return RunResult{ - .term = try child.wait(), .stdout = try stdout.toOwnedSlice(), .stderr = try stderr.toOwnedSlice(), + .term = try child.wait(), }; }