Skip to content

Commit

Permalink
Merge pull request #20192 from squeek502/fs-handle-leaks
Browse files Browse the repository at this point in the history
Fix handle leaks in `Dir.makeOpenPathAccessMaskW` and a `fs` test
  • Loading branch information
andrewrk authored Jun 5, 2024
2 parents 3b77f23 + 016e87e commit 8c04ffb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
7 changes: 5 additions & 2 deletions lib/std/fs/Dir.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
}

Expand Down
3 changes: 2 additions & 1 deletion lib/std/fs/test.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1161,7 +1161,8 @@ test "makepath existing directories" {
defer tmp.cleanup();

try tmp.dir.makeDir("A");
const tmpA = try tmp.dir.openDir("A", .{});
var tmpA = try tmp.dir.openDir("A", .{});
defer tmpA.close();
try tmpA.makeDir("B");

const testPath = "A" ++ fs.path.sep_str ++ "B" ++ fs.path.sep_str ++ "C";
Expand Down

0 comments on commit 8c04ffb

Please sign in to comment.