cpython/Objects/mimalloc
Sam Gross d76df75f51
gh-145615: Fix mimalloc page leak in the free-threaded build (gh-145626)
Fix three issues that caused mimalloc pages to be leaked until the
owning thread exited:

1. In _PyMem_mi_page_maybe_free(), move pages out of the full queue
   when relying on QSBR to defer freeing the page. Pages in the full
   queue are never searched by mi_page_queue_find_free_ex(), so a page
   left there is unusable for allocations.

2. Move _PyMem_mi_page_clear_qsbr() from _mi_page_free_collect() to
   _mi_page_thread_free_collect() where it only fires when all blocks
   on the page are free (used == 0). The previous placement was too
   broad: it cleared QSBR state whenever local_free was non-NULL, but
   _mi_page_free_collect() is called from non-allocation paths (e.g.,
   page visiting in mi_heap_visit_blocks) where the page is not being
   reused.

3. In _PyMem_mi_page_maybe_free(), use the page's heap tld to find the
   correct thread state for QSBR list insertion instead of
   PyThreadState_GET(). During stop-the-world pauses, the function may
   process pages belonging to other threads, so the current thread
   state is not necessarily the owner of the page.
2026-03-09 13:24:34 -04:00
..
prim gh-123826: Fix unused function warnings in mimalloc on NetBSD (#123827) 2024-09-09 13:22:28 -04:00
alloc-aligned.c gh-90815: Add mimalloc memory allocator (#109914) 2023-10-30 15:43:11 +00:00
alloc-override.c gh-90815: Add mimalloc memory allocator (#109914) 2023-10-30 15:43:11 +00:00
alloc-posix.c gh-90815: Add mimalloc memory allocator (#109914) 2023-10-30 15:43:11 +00:00
alloc.c Fix typos in docs, error messages and comments (#123336) 2024-08-28 14:41:04 +03:00
arena.c Fix typos in docs, error messages and comments (#123336) 2024-08-28 14:41:04 +03:00
bitmap.c Fix typos in comments (#120821) 2024-06-24 19:47:00 +02:00
bitmap.h Fix typos (#123775) 2024-09-09 14:58:26 +02:00
heap.c gh-145615: Fix mimalloc page leak in the free-threaded build (gh-145626) 2026-03-09 13:24:34 -04:00
init.c Fix typos (#123775) 2024-09-09 14:58:26 +02:00
options.c Fix typos in docs, error messages and comments (#123336) 2024-08-28 14:41:04 +03:00
os.c gh-123022: Fix crash with Py_Initialize in background thread (#123052) 2024-08-17 16:04:08 -04:00
page-queue.c gh-90815: Add mimalloc memory allocator (#109914) 2023-10-30 15:43:11 +00:00
page.c gh-145615: Fix mimalloc page leak in the free-threaded build (gh-145626) 2026-03-09 13:24:34 -04:00
random.c gh-90815: Add mimalloc memory allocator (#109914) 2023-10-30 15:43:11 +00:00
segment-map.c Fix typos (#123775) 2024-09-09 14:58:26 +02:00
segment.c gh-145615: Fix mimalloc page leak in the free-threaded build (gh-145626) 2026-03-09 13:24:34 -04:00
static.c gh-90815: Add mimalloc memory allocator (#109914) 2023-10-30 15:43:11 +00:00
stats.c gh-90815: Add mimalloc memory allocator (#109914) 2023-10-30 15:43:11 +00:00