| author | |
| committer | |
| log | 8c04ffba86dd3b09c1fccab91ed42b2ec63b4815 |
| tree | ec6498ac4b3da21a14590b03ca383127653721ab |
| parent | 3b77f23e760ef46c558ff8d3f45f7e477da644b2 |
| parent | 016e87e7efa0311fe360ca2f0ba2a6fa583b3fda |
| signature |
Fix handle leaks in `Dir.makeOpenPathAccessMaskW` and a `fs` test2 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(); | ||
| 1222 | 1220 | ||
| 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 | } |
| 1226 | 1229 |
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(); |
| 1162 | 1162 | ||
| 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"); |
| 1166 | 1167 | ||
| 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"; |