From e6a114eed043dd1ca50be1cab912662fa9150fda Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Fri, 30 Oct 2026 21:04:02 -0300 Subject: dump: a closed terminal brought back on a screen-state replica gets its emulator on the C heap, as terminal.create makes one (terminal.emulatorGpa): loadPane named no `.terminal` allocator, so its emulator was the rollback epoch's, and its screen replica's blobs, made with State.gpa, were freed with the C heap's behind the epoch at a client's end and again by it (H21: `double free or corruption` in Epoch.deinit at a hangup, `free(): invalid pointer` at a rejoin), and a rollback freed what a delta under a held copy made of them Co-Authored-By: Claude Opus 5.5 --- src/terminal.zig | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'src/terminal.zig') diff --git a/src/terminal.zig b/src/terminal.zig index d4238c83..86eec32d 100644 --- a/src/terminal.zig +++ b/src/terminal.zig @@ -607,6 +607,13 @@ pub fn takeMarks(state: *State, bytes: []const u8) void { /// A screen-state replica's emulators' allocator (`State.gpa`). pub const emulator_gpa = std.heap.c_allocator; +/// What a terminal's emulator is made with, by `create` or a pane's load +/// (dump.loadPane, a closed terminal brought back): `gpa`, but on a screen- +/// state replica `emulator_gpa`. A hosted build's: the web has no C heap. +pub fn emulatorGpa(gpa: std.mem.Allocator) std.mem.Allocator { + return if (comptime pardes.hosted) (if (pardes.tape.screenReplica()) emulator_gpa else gpa) else gpa; +} + /// A replica's speculation leaves an emulator be: it is the authority's /// (docs/next-daemon.md, phase 5), so the input waits for its order. fn authorityOnly(comptime why: []const u8) bool { @@ -936,8 +943,7 @@ pub fn create(gpa: std.mem.Allocator, cols: u16, rows: u16) !*Pane { const pane = try createDoc(gpa, cols, rows); errdefer gpa.destroy(pane); if (comptime !enabled) return pane; - // A screen-state replica is a hosted build's: the web has no C heap. - const own = if (comptime pardes.hosted) (if (pardes.tape.screenReplica()) emulator_gpa else gpa) else gpa; + const own = emulatorGpa(gpa); const state = try own.create(State); errdefer own.destroy(state); state.gpa = own; -- cgit v1.3