From 708ef45600b244fb8836000249848c3a561b1efb Mon Sep 17 00:00:00 2001 From: Luna Date: Tue, 18 Aug 2020 20:41:57 -0300 Subject: [PATCH] fix use-after-free on repl --- src/main.zig | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main.zig b/src/main.zig index 119009e..15e1524 100644 --- a/src/main.zig +++ b/src/main.zig @@ -60,9 +60,11 @@ pub fn doRepl(allocator: *std.mem.Allocator, args_it: anytype) !void { var scri_existing = try allocator.alloc(u8, total_bytes); _ = try file_read_opt.?.read(scri_existing); - // we can defer this because we copy the Command structs back to cmds + // we can't defer this directly because we copy the + // Command pointers to the cmds list. running deinit() directly + // would cause those pointers to be freed. var existing_cmds = try lang.parse(scri_existing); - defer existing_cmds.deinit(); + defer existing_cmds.list.deinit(); // copy the existing command list into the repl's command list for (existing_cmds.list.items) |existing_cmd| {