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 {...@@ -13,6 +13,8 @@ pub fn Main(comptime T: type) type {
13 pub fn do() !void {13 pub fn do() !void {
14 var gpa = std.heap.GeneralPurposeAllocator(.{}){};14 var gpa = std.heap.GeneralPurposeAllocator(.{}){};
15 const alloc = &gpa.allocator;15 const alloc = &gpa.allocator;
16 defer _ = gpa.deinit();
17
16 const max_size = std.math.maxInt(usize);18 const max_size = std.math.maxInt(usize);
1719
18 //20 //
...@@ -38,8 +40,12 @@ pub fn Main(comptime T: type) type {...@@ -38,8 +40,12 @@ pub fn Main(comptime T: type) type {
3840
39 var line_num: usize = 1;41 var line_num: usize = 1;
40 std.debug.print("\n", .{});42 std.debug.print("\n", .{});
43
44 const arena = &std.heap.ArenaAllocator.init(alloc);
41 while (true) {45 while (true) {
42 const line = r.readUntilDelimiterAlloc(alloc, '\n', max_size) catch |e| if (e == error.EndOfStream) break else return e;46 const line = r.readUntilDelimiterAlloc(alloc, '\n', max_size) catch |e| if (e == error.EndOfStream) break else return e;
47 defer alloc.free(line);
48
43 if (line.len == 0) {49 if (line.len == 0) {
44 continue;50 continue;
45 }51 }
...@@ -47,7 +53,8 @@ pub fn Main(comptime T: type) type {...@@ -47,7 +53,8 @@ pub fn Main(comptime T: type) type {
47 continue;53 continue;
48 }54 }
4955
50 if (!(try T.exec(alloc, line, w))) {56 if (!(try T.exec(&arena.allocator, line, w))) {
57 arena.deinit();
51 break;58 break;
52 }59 }
5360