authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-05-31 12:32:27 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-05-31 12:32:27 -07:00
logb0ea5ddd2ec4f78e2f21ba3922f1ba87fad69fa1
treec1a9851e98c6830836412f647a0ecc23c46aefb5
parent30ff725e47a66dbfeae96e64257c161bae181bf8

gen- deinit memory and get rid of leaks


1 files changed, 8 insertions(+), 1 deletions(-)

scripts/_common.zig+8-1
......@@ -13,6 +13,8 @@ pub fn Main(comptime T: type) type {
1313 pub fn do() !void {
1414 var gpa = std.heap.GeneralPurposeAllocator(.{}){};
1515 const alloc = &gpa.allocator;
16 defer _ = gpa.deinit();
17
1618 const max_size = std.math.maxInt(usize);
1719
1820 //
......@@ -38,8 +40,12 @@ pub fn Main(comptime T: type) type {
3840
3941 var line_num: usize = 1;
4042 std.debug.print("\n", .{});
43
44 const arena = &std.heap.ArenaAllocator.init(alloc);
4145 while (true) {
4246 const line = r.readUntilDelimiterAlloc(alloc, '\n', max_size) catch |e| if (e == error.EndOfStream) break else return e;
47 defer alloc.free(line);
48
4349 if (line.len == 0) {
4450 continue;
4551 }
......@@ -47,7 +53,8 @@ pub fn Main(comptime T: type) type {
4753 continue;
4854 }
4955
50 if (!(try T.exec(alloc, line, w))) {
56 if (!(try T.exec(&arena.allocator, line, w))) {
57 arena.deinit();
5158 break;
5259 }
5360