Close source file after reading it in zig fmt

master
Alexandros Naskos 2020-06-21 17:03:02 +03:00 committed by Andrew Kelley
parent 56220449ab
commit b70c38c33c
1 changed files with 4 additions and 1 deletions

View File

@ -736,7 +736,8 @@ fn fmtPathFile(
sub_path: []const u8,
) FmtError!void {
const source_file = try dir.openFile(sub_path, .{});
defer source_file.close();
var file_closed = false;
errdefer if (!file_closed) source_file.close();
const stat = try source_file.stat();
@ -748,6 +749,8 @@ fn fmtPathFile(
error.ConnectionTimedOut => unreachable,
else => |e| return e,
};
source_file.close();
file_closed = true;
defer fmt.gpa.free(source_code);
// Add to set after no longer possible to get error.IsDir.