diff --git a/src/lang.zig b/src/lang.zig index 98b1e77..5ded695 100644 --- a/src/lang.zig +++ b/src/lang.zig @@ -479,25 +479,24 @@ pub const CommandList = struct { pub fn deinit(self: *Self) void { for (self.list.items) |cmd_ptr| { - //self.list.allocator.destroy(cmd_ptr); inline for (@typeInfo(Command.Tag).Enum.fields) |field| { if (cmd_ptr.tag == @field(Command.Tag, field.name)) { const actual_tag = @field(Command.Tag, field.name); // if we find a match on the tag, we can get the type const typ = Command.tagToType(actual_tag); - _ = typ; - // TODO fix - - //inline for (@typeInfo(typ).Struct.fields) |cmd_field| { - // switch (cmd_field.field_type) { - // []u8, []const u8 => self.list.allocator.destroy(@field(typ, cmd_field.name)), - // else => {}, - // } - //} + const inner_command = cmd_ptr.cast(typ).?; + inline for (@typeInfo(typ).Struct.fields) |cmd_field| { + switch (cmd_field.field_type) { + []u8, []const u8 => self.list.allocator.free(@field(inner_command, cmd_field.name)), + else => {}, + } + } } } + + self.list.allocator.destroy(cmd_ptr); } self.list.deinit(); }