authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-06-05 13:45:35-04:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2024-06-05 13:45:35-04:00
log8c04ffba86dd3b09c1fccab91ed42b2ec63b4815
treeec6498ac4b3da21a14590b03ca383127653721ab
parent3b77f23e760ef46c558ff8d3f45f7e477da644b2
parent016e87e7efa0311fe360ca2f0ba2a6fa583b3fda
signaturebadge-check Signed by PGP key B5690EEEBB952194

Merge pull request #20192 from squeek502/fs-handle-leaks

Fix handle leaks in `Dir.makeOpenPathAccessMaskW` and a `fs` test

2 files changed, 7 insertions(+), 3 deletions(-)

lib/std/fs/Dir.zig+5-2
...@@ -1217,10 +1217,13 @@ fn makeOpenPathAccessMaskW(self: Dir, sub_path: []const u8, access_mask: u32, no...@@ -1217,10 +1217,13 @@ fn makeOpenPathAccessMaskW(self: Dir, sub_path: []const u8, access_mask: u32, no
1217 },1217 },
1218 else => |e| return e,1218 else => |e| return e,
1219 };1219 };
1220 // Don't leak the intermediate file handles
1221 errdefer if (result) |*dir| dir.close();
12221220
1223 component = it.next() orelse return result.?;1221 component = it.next() orelse return result.?;
1222
1223 // Don't leak the intermediate file handles
1224 if (result) |*dir| {
1225 dir.close();
1226 }
1224 }1227 }
1225}1228}
12261229
lib/std/fs/test.zig+2-1
...@@ -1161,7 +1161,8 @@ test "makepath existing directories" {...@@ -1161,7 +1161,8 @@ test "makepath existing directories" {
1161 defer tmp.cleanup();1161 defer tmp.cleanup();
11621162
1163 try tmp.dir.makeDir("A");1163 try tmp.dir.makeDir("A");
1164 const tmpA = try tmp.dir.openDir("A", .{});1164 var tmpA = try tmp.dir.openDir("A", .{});
1165 defer tmpA.close();
1165 try tmpA.makeDir("B");1166 try tmpA.makeDir("B");
11661167
1167 const testPath = "A" ++ fs.path.sep_str ++ "B" ++ fs.path.sep_str ++ "C";1168 const testPath = "A" ++ fs.path.sep_str ++ "B" ++ fs.path.sep_str ++ "C";