properly fix memleaks

This commit is contained in:
Luna 2022-04-28 00:28:07 -03:00
parent 2796b654e5
commit 6b2ce7e425

View file

@ -479,26 +479,25 @@ 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();
}