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

Fix handle leaks in `Dir.makeOpenPathAccessMaskW` and a `fs` test
This commit is contained in:
Andrew Kelley 2024-06-05 13:45:35 -04:00 committed by GitHub
commit 8c04ffba86
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 7 additions and 3 deletions

View File

@ -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();
}
}
}

View File

@ -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";