authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-12-26 14:08:45-08:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-12-26 19:58:56-08:00
log0dbcf97551765d3abbaea5fb0b9e94e5e0be1b14
treeb98ef422ef235478ae678793905ef8e3f98d9e84
parenteb0d5b1377089ff6c51ffc6de6963b9897c906e4

std.Io.Threaded: fix resource leak in dirRealPathFilePosix

it should unconditionally close the opened file descriptor, not only on error.

1 files changed, 8 insertions(+), 7 deletions(-)

lib/std/Io/Threaded.zig+8-7
......@@ -4165,7 +4165,7 @@ fn dirRealPathFilePosix(userdata: ?*anyopaque, dir: Dir, sub_path: []const u8, o
41654165 },
41664166 }
41674167 };
4168 errdefer posix.close(fd);
4168 defer posix.close(fd);
41694169 return realPathPosix(current_thread, fd, out_buffer);
41704170}
41714171
......@@ -4290,16 +4290,17 @@ fn realPathPosix(current_thread: *Thread, fd: posix.fd_t, out_buffer: []u8) File
42904290 try current_thread.checkCancel();
42914291 continue;
42924292 },
4293 else => |e| {
4293 .BADF => {
42944294 current_thread.endSyscall();
4295 switch (e) {
4296 .BADF => return error.FileNotFound,
4297 else => |err| return posix.unexpectedErrno(err),
4298 }
4295 return error.FileNotFound;
4296 },
4297 else => |err| {
4298 current_thread.endSyscall();
4299 return posix.unexpectedErrno(err);
42994300 },
43004301 }
43014302 }
4302 const len = std.mem.indexOfScalar(u8, &k_file.path, 0) orelse k_file.path.len;
4303 const len = std.mem.findScalar(u8, &k_file.path, 0) orelse k_file.path.len;
43034304 if (len == 0) return error.NameTooLong;
43044305 return len;
43054306 },