commit 4de2b1ea65e6b54cedfe56268a8bf8e9446addb0 (tree)
parent c104e864429e1b62aa68423171dc6d94d3f4ee0e
Author: Alex Kladov <aleksey.kladov@gmail.com>
Date: Thu, 30 Jan 2025 12:01:53 +0000
std: don't leak a process in Child.run in case of an error
Closes: #22433
Diffstat:
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git 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(),
};
}