From b0ea5ddd2ec4f78e2f21ba3922f1ba87fad69fa1 Mon Sep 17 00:00:00 2001 From: Meghan Denny Date: Mon, 31 May 2021 12:32:27 -0700 Subject: [PATCH] gen- deinit memory and get rid of leaks --- scripts/_common.zig | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/scripts/_common.zig b/scripts/_common.zig index 7072d11d3c253b0af41f2b0c4969bfbfd7f4351e..21614b9a050868235dfde41286542c0a51424f9c 100644 --- a/scripts/_common.zig +++ b/scripts/_common.zig @@ -13,6 +13,8 @@ pub fn Main(comptime T: type) type { pub fn do() !void { var gpa = std.heap.GeneralPurposeAllocator(.{}){}; const alloc = &gpa.allocator; + defer _ = gpa.deinit(); + const max_size = std.math.maxInt(usize); // @@ -38,8 +40,12 @@ pub fn Main(comptime T: type) type { var line_num: usize = 1; std.debug.print("\n", .{}); + + const arena = &std.heap.ArenaAllocator.init(alloc); while (true) { const line = r.readUntilDelimiterAlloc(alloc, '\n', max_size) catch |e| if (e == error.EndOfStream) break else return e; + defer alloc.free(line); + if (line.len == 0) { continue; } @@ -47,7 +53,8 @@ pub fn Main(comptime T: type) type { continue; } - if (!(try T.exec(alloc, line, w))) { + if (!(try T.exec(&arena.allocator, line, w))) { + arena.deinit(); break; } -- 2.54.0