From b83e1ee47fd6e8a9bfa539f5f486401c6fbed342 Mon Sep 17 00:00:00 2001 From: Nic Gaffney Date: Wed, 7 Aug 2024 16:56:22 -0500 Subject: Fixed memory leaks --- src/symtable.zig | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'src/symtable.zig') diff --git a/src/symtable.zig b/src/symtable.zig index f37ee12..cc041c5 100644 --- a/src/symtable.zig +++ b/src/symtable.zig @@ -196,6 +196,7 @@ pub const Populator = struct { std.debug.print("Populated Function {s}\n", .{fun.ident.ident}); if (!try table.insert(fun.ident.ident, symbol)) return error.FailedToInsert; const children = try stmt.children(self.allocator); + defer self.allocator.free(children); for (children) |child| try self.populateSymtable(&child); }, @@ -221,17 +222,21 @@ pub const Populator = struct { const output = try self.allocator.create(SymbType); output.* = if (retType) |typ| table.getType(typ).? else SymbType.Void; + const typ = SymbType{ + .Function = .{ + .output = output, + .input = input, + }, + }; + const id = self.reserveId(); + + _ = try table.insert("func_" ++ .{@as(u8, @truncate(id))}, typ.toSymb()); return Symbol{ .Value = SymbValue{ .mut = true, - .id = self.reserveId(), - .typ = SymbType{ - .Function = .{ - .input = input, - .output = output, - }, - }, + .id = id, + .typ = typ, }, }; } -- cgit v1.2.3