diff --git a/src/lang.zig b/src/lang.zig index 2f2b4ac..3ad0c41 100644 --- a/src/lang.zig +++ b/src/lang.zig @@ -523,6 +523,11 @@ pub const Lang = struct { ) !void { // Based on the command struct fields, we can parse the arguments. var cmd = try self.allocator.create(command_struct); + + // we already add the command to the list to prevent memory leaks + // by commands that error out + try commands.append(&cmd.base); + const is_lv2_command = switch (command_struct.base_tag) { .noop, .load, .quicksave, .runqs, .rotate => false, else => true, @@ -598,13 +603,12 @@ pub const Lang = struct { cmd.base.tag = command_struct.base_tag; const command = cmd.base.cast(command_struct).?; std.debug.warn("cmd: {s}\n", .{command}); - - try commands.append(&cmd.base); } pub fn parse(self: *Lang, data: []const u8) !CommandList { var splitted_it = std.mem.split(data, ";"); var cmds = CommandList.init(self.allocator); + errdefer cmds.deinit(); while (splitted_it.next()) |stmt_orig| { self.line += 1;