@@ -61,9 +61,10 @@ pub fn main() !void {
6161 // close read side of pipe
6262 if (comptime builtin .target .isDarwin ()) {
6363 {
64+ // less time for leaking the file descriptor, if it is closed immediately
6465 child_proc .posix_actions = try os .posix_spawn .Actions .init ();
6566 errdefer child_proc .posix_actions .? .deinit ();
66- try child_proc .posix_actions .? .close (pipe [0 ]);
67+ try child_proc .posix_actions .? .close (pipe [1 ]);
6768 errdefer child_proc .posix_actions .? .deinit ();
6869 }
6970 }
@@ -78,19 +79,29 @@ pub fn main() !void {
7879 try child_proc .spawn ();
7980 }
8081
81- try std .os .disableFileInheritance (pipe [1 ]);
82+ if (builtin .os .tag == .windows ) {
83+ try std .os .disableFileInheritance (pipe [1 ].? );
84+ } else {
85+ try std .os .disableFileInheritance (pipe [1 ]);
86+ }
87+
8288 // check that disableFileInheritance was successful
8389 if (builtin .target .os .tag == .windows ) {
8490 var handle_flags : windows.DWORD = undefined ;
85- try windows .GetHandleInformation (pipe [1 ], & handle_flags );
91+ try windows .GetHandleInformation (pipe [1 ].? , & handle_flags );
8692 std .debug .assert (handle_flags & windows .HANDLE_FLAG_INHERIT != 0 );
8793 } else {
8894 const fcntl_flags = try os .fcntl (pipe [1 ], os .F .GETFD , 0 );
8995 try std .testing .expect ((fcntl_flags & os .FD_CLOEXEC ) != 0 );
9096 }
9197
92- var file_out = std.fs.File { .handle = pipe [1 ] };
93- defer file_out .close ();
98+ // do we want another extra prong for darwin?
99+ var file_out = if (builtin .target .os .tag == .windows )
100+ std.fs.File { .handle = pipe [1 ].? }
101+ else
102+ std.fs.File { .handle = pipe [1 ] };
103+
104+ defer if (comptime ! builtin .target .isDarwin ()) file_out .close ();
94105 const file_out_writer = file_out .writer ();
95106 try file_out_writer .writeAll ("test123\x17 " ); // ETB = \x17
96107 const ret_val = try child_proc .wait ();
0 commit comments