szn

Bug 396 — border_format_cached has two owners

396. border_format_cached has two owners: expanded with the session arena but freed with the server GPA on cache invalidation

Severity: CRITICAL Status: ✅ RESOLVED

renderToDisplayClient expands pane-border-format through format_mod.expand(pb.pane.screen.grid.allocator, ...) — grid.allocator is the session ArenaAllocator (threaded Session.newWindow → Window.init). The cache-invalidation path then frees the previous value with self.allocator, the server GPA:

const expanded = format_mod.expand(pb.pane.screen.grid.allocator, pane_border_fmt_str, &ctx) ...;
if (pb.pane.border_format_cached) |old_exp| {
    self.allocator.free(old_exp);   // GPA-free of an arena-interior pointer: UB
}

Pane.deinit (window.zig:54) frees the same field with grid.allocator — the field is owned by two allocators depending on path. GPA free of an arena pointer: Debug builds panic, ReleaseFast corrupts the heap.

Deterministic trigger: change pane-border-format twice (cmd.zig:960-962 bumps border_format_gen), next render hits the evict branch. Introduced by the #304/#307 caching fix, which never checked which allocator owned the cached slice.

Fix: free old_exp with pb.pane.screen.grid.allocator (matching the expand allocator).