From 5490021ab7d97425a44b78e218b5462f960d9c9d Mon Sep 17 00:00:00 2001 From: Ryan Liptak Date: Tue, 4 Jun 2024 18:44:07 -0700 Subject: [PATCH] Dir.makeOpenPathAccessMaskW: Fix leaking intermediate directory handles Fixes a regression introduced in 67455c5e70e86dbb7805ff9a415f1b13b14f36da. The `errdefer` cannot run since its not possible for an error to occur, and we don't want it to run on the last handle, so we move the closing back down to where it was before 67455c5e70e86dbb7805ff9a415f1b13b14f36da. --- lib/std/fs/Dir.zig | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/std/fs/Dir.zig b/lib/std/fs/Dir.zig index 192a0d4b3a..16b1cc2aaa 100644 --- a/lib/std/fs/Dir.zig +++ b/lib/std/fs/Dir.zig @@ -1217,10 +1217,13 @@ fn makeOpenPathAccessMaskW(self: Dir, sub_path: []const u8, access_mask: u32, no }, else => |e| return e, }; - // Don't leak the intermediate file handles - errdefer if (result) |*dir| dir.close(); component = it.next() orelse return result.?; + + // Don't leak the intermediate file handles + if (result) |*dir| { + dir.close(); + } } }