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...@@ -4165,7 +4165,7 @@ fn dirRealPathFilePosix(userdata: ?*anyopaque, dir: Dir, sub_path: []const u8, o
4165 },4165 },
4166 }4166 }
4167 };4167 };
4168 errdefer posix.close(fd);4168 defer posix.close(fd);
4169 return realPathPosix(current_thread, fd, out_buffer);4169 return realPathPosix(current_thread, fd, out_buffer);
4170}4170}
41714171
...@@ -4290,16 +4290,17 @@ fn realPathPosix(current_thread: *Thread, fd: posix.fd_t, out_buffer: []u8) File...@@ -4290,16 +4290,17 @@ fn realPathPosix(current_thread: *Thread, fd: posix.fd_t, out_buffer: []u8) File
4290 try current_thread.checkCancel();4290 try current_thread.checkCancel();
4291 continue;4291 continue;
4292 },4292 },
4293 else => |e| {4293 .BADF => {
4294 current_thread.endSyscall();4294 current_thread.endSyscall();
4295 switch (e) {4295 return error.FileNotFound;
4296 .BADF => return error.FileNotFound,4296 },
4297 else => |err| return posix.unexpectedErrno(err),4297 else => |err| {
4298 }4298 current_thread.endSyscall();
4299 return posix.unexpectedErrno(err);
4299 },4300 },
4300 }4301 }
4301 }4302 }
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;
4303 if (len == 0) return error.NameTooLong;4304 if (len == 0) return error.NameTooLong;
4304 return len;4305 return len;
4305 },4306 },