Severity: LOW Status: Fixed
None observable today. Every loop that holds a *dc into
self.display_clients.items either calls only functions that never mutate
display_clients (flushDisplayClient, appendClientOut*), or breaks
immediately after the call. registerDisplayClient (append) is only reached
from handleClient’s .identify_term case and removeClient (swapRemove)
only from detach/error paths — none of which are reachable from inside the
loops. The hazard is latent: any future code that appends or removes a
display client while a *dc is held re-opens the bug.
self.display_clients is std.ArrayList(DisplayClient) (values, not
pointers). An append (registerDisplayClient, server.zig:2430) can reallocate
the backing buffer, moving every element; a swapRemove (removeClient,
server.zig:2612) moves the last element into the hole and shrinks the length.
Consequently:
// src/server/server.zig:3035 — renderToDisplayClient
for (self.display_clients.items) |*dc| {
...
_ = self.flushDisplayClient(dc); // safe: never mutates display_clients
...
}
is a pointer into the array buffer held across the body. This is the same
shape as holding reader = client_readers.get(fd) across the dispatch loop
in #428/#443 (sub-form (b): pointer into a reallocatable container held
across a call that can resize it). The difference is that the mutators are
currently unreachable from the hold sites, so it is a defensive gap rather
than a live use-after-free.
Note also that DisplayClient contains ArrayList fields (out_buf,
last_cells, bounds_buf) and a Screen — copying the struct by value when
the array grows is safe because those are heap buffers whose pointers are
copied, but any code holding &dc.field across an append would see stale
fields.
display_clients to an ArrayList(*DisplayClient) of
heap-allocated structs (destroyed in removeClient/deinit), so element
pointers survive append/swapRemove — matching how sessions, windows,
and panes already store pointers.*dc after any call that could
mutate the array, and never hold a *dc across such a call.*dc, asserting the held pointer is
not used afterwards.Fixed:
self.display_clients from std.ArrayList(DisplayClient) to std.ArrayList(*DisplayClient).DisplayClient is heap-allocated in addDisplayClient / registerDisplayClient and freed upon removeClient / Server.deinit.src/server/server.zig now use |dc| directly without taking pointers into the reallocatable display_clients.items slice.display client pointer remains stable across display_clients reallocations — bug #450 verifying that pointer addresses to existing clients remain valid across forced buffer reallocations.