core: free allocated writes in read-only mode (#13574)

Read-only filtering happens in Surface.queueIo after callers construct
the message. This early return leaked write_alloc payloads because the
IO thread never receives them and therefore does not perform its normal
cleanup.
This commit is contained in:
Mitchell Hashimoto
2026-08-03 09:14:59 -07:00
committed by GitHub

View File

@@ -872,9 +872,13 @@ fn queueIo(
switch (msg) {
.write_small,
.write_stable,
.write_alloc,
=> return,
.write_alloc => |v| {
v.alloc.free(v.data);
return;
},
else => {},
}
}
@@ -6064,3 +6068,18 @@ fn presentSurface(self: *Surface) !void {
pub fn getProcessInfo(self: *Surface, comptime info: ProcessInfo) ?ProcessInfo.Type(info) {
return self.io.getProcessInfo(info);
}
test "queueIo frees allocated writes in readonly mode" {
const testing = std.testing;
const surface = try testing.allocator.create(Surface);
defer testing.allocator.destroy(surface);
surface.readonly = true;
// queueIo must free allocated writes in read-only mode.
const data = try testing.allocator.dupe(u8, "\x1b]lGhostty\x1b\\");
surface.queueIo(.{ .write_alloc = .{
.alloc = testing.allocator,
.data = data,
} }, .unlocked);
}