Skip to content

Commit

Permalink
Merge pull request #2878 from ghostty-org/push-wopvxurkxzwk
Browse files Browse the repository at this point in the history
terminal: PageList.reset has to zero arena memory to avoid reuse
  • Loading branch information
mitchellh authored Dec 3, 2024
2 parents 91ae0e1 + e712314 commit 50dc4b7
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/terminal/PageList.zig
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,25 @@ pub fn reset(self: *PageList) void {
.retain_with_limit = page_count * NodePool.item_size,
});

// Our page pool relies on mmap to zero our page memory. Since we're
// retaining a certain amount of memory, it won't use mmap and won't
// be zeroed. This block zeroes out all the memory in the pool arena.
{
// Note: we only have to do this for the page pool because the
// nodes are always fully overwritten on each allocation.
const page_arena = &self.pool.pages.arena;
var it = page_arena.state.buffer_list.first;
while (it) |node| : (it = node.next) {
// The fully allocated buffer
const alloc_buf = @as([*]u8, @ptrCast(node))[0..node.data];

// The buffer minus our header
const BufNode = @TypeOf(page_arena.state.buffer_list).Node;
const data_buf = alloc_buf[@sizeOf(BufNode)..];
@memset(data_buf, 0);
}
}

// Initialize our pages. This should not be able to fail since
// we retained the capacity for the minimum number of pages we need.
self.pages, self.page_size = initPages(
Expand Down

0 comments on commit 50dc4b7

Please sign in to comment.