If killed when the pipe is still open,
the process could turn into a zombie.
---
On 2024-08-05 at 16:44+09:00, Nguyễn Gia Phong wrote:
> The file is not closed if readToEndAlloc return an error.
> [...] I will send out a v2 addressing this
I forgot to do it so here goes the patch on top of that d-;
src/util/utilprocess.zig | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/src/util/utilprocess.zig b/src/util/utilprocess.zig
index 45346a3cd93d..4e73504b83d3 100644
--- a/src/util/utilprocess.zig+++ b/src/util/utilprocess.zig
@@ -66,9 +66,11 @@ pub fn run_subprocess(
if (set_process_id_opt_ptr_opt) |pid_ptr|
pid_ptr.* = pid;
- const file = std.fs.File{ .handle = pipe[0] };- const stdout = try file.readToEndAlloc(allocator, 10_000_000);- std.posix.close(pipe[0]);+ const stdout = blk: {+ defer std.posix.close(pipe[0]);+ const file = std.fs.File{ .handle = pipe[0] };+ break :blk try file.readToEndAlloc(allocator, 10_000_000);+ }; const result = std.posix.waitpid(pid, 0);
// Spawn failure of foreign binaries are reported as successful:
// https://github.com/ziglang/zig/pull/14866
--
2.45.2