File: src/server/server.zig:2717-2722 (cf. window.zig:265-269, 469-478)
Severity: CRITICAL
Status: ✅ FIXED
renderToDisplayClient’s auto-rename now calls win.setName(proc_name) —
copying into the inline name_buf, which is the only way Window.name is ever
set (init, rename-window, OSC titles) — and keeps last_foreground_name as a
separately owned dupe. No free of win.name, no aliasing.
Test: auto-rename: name stays in name_buf, cache never aliases it —
bug #358 (two consecutive renames plus a later OSC title, asserting inline
storage, no aliasing, and clean single free at deinit under
testing.allocator).
Running e.g. vim then htop in an automatic-rename window triggers:
win.allocator.free(win.name) — but when the name came from an OSC title
callback, Window.name points into the embedded name_buf, not the heap.
Freeing it is an invalid free of an interior struct pointer.win.name and win.last_foreground_name are set to the same duped
slice. On the next rename both fields are freed → double free.name == duped, any later setName() (OSC title) repoints name at
name_buf, permanently orphaning duped.Masked today because these frees go through the session arena (no-op unless most-recent allocation); under any GPA this is corruption on the second rename.
Never free win.name here (it is not owned by this code path — see the
window.zig:574-579 test documenting “name is not owned”); dupe separately for
last_foreground_name, freeing only the previous last_foreground_name if it
is tracked as owned. Add an ownership comment on both fields plus a regression
test simulating two consecutive renames followed by an OSC title change.