szn

Bug 230 — reflowCursorInternal double-frees history, leaks memory, and corrupts ring buffer index

230. reflowCursorInternal double-frees history, leaks memory, and corrupts ring buffer index

File: src/grid.zig:820–895 Severity: CRITICAL Status: ✅ FIXED

  1. for (old_history.items) |*l| l.deinit(allocator); frees all history slots, including evicted elements before old_history_start.
  2. If rewrap or allocator.dupe fails, errdefer cleans up new_lines but leaks old_lines and old_history.
  3. self.history_start is left un-reset after setting self.history = new_history.

Impact: SIGSEGV double-free crashes during window resize, memory leaks under OOM, and out-of-bounds indexing.

Fix: Save old_history_start. Deinitialize old_history.items[old_history_start..]. Add errdefer restoring old_lines, old_history, and old_history_start. Set self.history_start = 0.