Close source file after reading it in zig fmt

This commit is contained in:
Alexandros Naskos 2020-06-21 17:03:02 +03:00 committed by Andrew Kelley
parent 56220449ab
commit b70c38c33c

View File

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