szn

Bug 217 — reflowCursorInternal destroys old grid lines before new lines are committed — unrecoverable on OOM

217. reflowCursorInternal destroys old grid lines before new lines are committed — unrecoverable on OOM

File: src/grid.zig:663–671 Severity: CRITICAL Status: ✅ FIXED — moved old line deinit to after the split logic so OOM during allocation doesn’t corrupt the grid.

for (old_lines.items) |*l| l.deinit(allocator);
old_lines.deinit(allocator);
for (old_history.items) |*l| l.deinit(allocator);
old_history.deinit(allocator);

The old grid lines and history are fully deinitialized and freed before new_lines is split into the new visible + history portions (lines 678–714). If any allocation inside that split logic fails (e.g. allocator.dupe for the visible portion on line 685), the grid is left in a corrupted state: self.lines and self.history are .empty, the old data is freed, and new_lines is only cleaned up by the errdefer but never recovered. The grid is permanently destroyed with no way to roll back.

Fix: Defer the destruction of old_lines/old_history until after new_lines is successfully split, or use a temporary swap-and-commit pattern.