From adc8a50289f17ba15867f6d8e45844f57ee1aaa8 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Thu, 5 Nov 2026 01:16:27 -0300 Subject: ninep tree: a ctl line's bytes are the gpa's until its write is answered, where they were the step's scratch: a `size` line resizes and syncs (a step, which resets the scratch under it) and then quotes its value in a refusal, so the refusal read freed memory; the base kept the arena's buffer by luck, and the merged line's bigger steps freed it (a segfault in the behaviour test 'size sets the screen of a session no frontend is attached to') Co-Authored-By: Claude Fable 5.1 Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge --- src/ninep/tree.zig | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/ninep/tree.zig') diff --git a/src/ninep/tree.zig b/src/ninep/tree.zig index b55065fd..53bec357 100644 --- a/src/ninep/tree.zig +++ b/src/ninep/tree.zig @@ -1295,7 +1295,11 @@ fn writeLines(p: *Pardes, req: Req, target: Target) Reply { } o.named = true; } - const whole = p.scratch.allocator().dupe(u8, o.pending.items[0..end]) catch return Reply.fail(req.tag, E.NOMEM); + // The line outlives any step its command runs (a `size` resizes and + // syncs, then quotes its value in a refusal): the step's scratch is + // reset under it, so the line is the gpa's until the write is answered. + const whole = p.gpa.dupe(u8, o.pending.items[0..end]) catch return Reply.fail(req.tag, E.NOMEM); + defer p.gpa.free(whole); const rest = o.pending.items.len - end; std.mem.copyForwards(u8, o.pending.items[0..rest], o.pending.items[end..]); o.pending.shrinkRetainingCapacity(rest); -- cgit v1.3