prevent memleaks on parse errors
This commit is contained in:
parent
ea3850b99d
commit
b195577dee
1 changed files with 6 additions and 2 deletions
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue