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{...@@ -270,11 +270,9 @@ const FmtError = error{
270 FileBusy,270 FileBusy,
271} || fs.File.OpenError;271} || fs.File.OpenError;
272272
273fn fmtPath(fmt: *Fmt, file_path_ref: []const u8, check_mode: bool) FmtError!void {273fn fmtPath(fmt: *Fmt, file_path: []const u8, check_mode: bool) FmtError!void {
274 const file_path = try std.mem.dupe(fmt.allocator, u8, file_path_ref);274 if (fmt.seen.exists(file_path)) return;
275 defer fmt.allocator.free(file_path);275 try fmt.seen.put(file_path);
276
277 if (try fmt.seen.put(file_path, {})) |_| return;
278276
279 const source_code = io.readFileAlloc(fmt.allocator, file_path) catch |err| switch (err) {277 const source_code = io.readFileAlloc(fmt.allocator, file_path) catch |err| switch (err) {
280 error.IsDir, error.AccessDenied => {278 error.IsDir, error.AccessDenied => {
...@@ -341,7 +339,7 @@ const Fmt = struct {...@@ -341,7 +339,7 @@ const Fmt = struct {
341 color: errmsg.Color,339 color: errmsg.Color,
342 allocator: *mem.Allocator,340 allocator: *mem.Allocator,
343341
344 const SeenMap = std.StringHashMap(void);342 const SeenMap = std.BufSet;
345};343};
346344
347fn printErrMsgToFile(345fn printErrMsgToFile(