diff --git a/docs/changelog.rst b/docs/changelog.rst index 0941f4cd6..1c51c4c3c 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -226,6 +226,8 @@ Detailed list of changes - scroll-window remote control command: Fix a regression that broke scrolling by pages (:iss:`10253`) +- Bypass libc malloc for history buffer to avoid libc pool policies causing apparent memory leak (:pull:`10254`) + 0.47.4 [2026-06-15] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/kitty/history.c b/kitty/history.c index 5a1de92ff..7c7097480 100644 --- a/kitty/history.c +++ b/kitty/history.c @@ -25,6 +25,8 @@ add_segment(HistoryBuf *self, index_type num) { const size_t segment_size = cpu_cells_size + gpu_cells_size + SEGMENT_SIZE * sizeof(LineAttrs); if (num > SIZE_MAX / segment_size) fatal("History buffer segment allocation is too large"); const size_t mmap_size = num * segment_size; + // We use mmap to avoid fragmentation in libc malloc pool, see + // https://github.com/kovidgoyal/kitty/pull/10254 char *mem = mmap(NULL, mmap_size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0); if (mem == MAP_FAILED) fatal("Out of memory allocating new history buffer segment"); char *needs_free = mem;