properly fix memleaks
This commit is contained in:
parent
2796b654e5
commit
6b2ce7e425
1 changed files with 9 additions and 10 deletions
19
src/lang.zig
19
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();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue