authorgravatar for robin@voetter.nlRobin Voetter <robin@voetter.nl> 2019-12-09 21:20:42+01:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-12-10 11:09:29-05:00
logc519bb02df4df0938c5ac12e8b4e8f8ab503df63
tree2583e067323f7356709b115f96fac2689d02e1c2
parentd568db23867605139311f5e6909dfb1f9b92b4ba
signature Commit is signed but in an unrecognized format.

Fix usage of freed memory in zig fmt


1 files changed, 4 insertions(+), 6 deletions(-)

src-self-hosted/stage1.zig+4-6
......@@ -270,11 +270,9 @@ const FmtError = error{
270270 FileBusy,
271271} || fs.File.OpenError;
272272
273fn fmtPath(fmt: *Fmt, file_path_ref: []const u8, check_mode: bool) FmtError!void {
274 const file_path = try std.mem.dupe(fmt.allocator, u8, file_path_ref);
275 defer fmt.allocator.free(file_path);
276
277 if (try fmt.seen.put(file_path, {})) |_| return;
273fn fmtPath(fmt: *Fmt, file_path: []const u8, check_mode: bool) FmtError!void {
274 if (fmt.seen.exists(file_path)) return;
275 try fmt.seen.put(file_path);
278276
279277 const source_code = io.readFileAlloc(fmt.allocator, file_path) catch |err| switch (err) {
280278 error.IsDir, error.AccessDenied => {
......@@ -341,7 +339,7 @@ const Fmt = struct {
341339 color: errmsg.Color,
342340 allocator: *mem.Allocator,
343341
344 const SeenMap = std.StringHashMap(void);
342 const SeenMap = std.BufSet;
345343};
346344
347345fn printErrMsgToFile(