https://github.com/python/cpython/commit/8754abc358aff62feb37dd5d30f16eec06d9bbaa
commit: 8754abc358aff62feb37dd5d30f16eec06d9bbaa
branch: 3.13
author: Miss Islington (bot) <[email protected]>
committer: ZeroIntensity <[email protected]>
date: 2026-06-11T21:18:14-04:00
summary:

[3.13] gh-151065: Copy fix for memory leak from mimalloc upstream (GH-151066) 
(GH-151385)

Applies 
https://github.com/microsoft/mimalloc/commit/d7a72c4912943e8aaf135e465ca5ea229ea96646
 to our copy of mimalloc.
(cherry picked from commit 80f9467434cecbc4e97b853b3876de13e75aec38)

Co-authored-by: Peter Bierma <[email protected]>

files:
A 
Misc/NEWS.d/next/Core_and_Builtins/2026-06-08-05-31-22.gh-issue-151065._o_31F.rst
M Objects/mimalloc/init.c

diff --git 
a/Misc/NEWS.d/next/Core_and_Builtins/2026-06-08-05-31-22.gh-issue-151065._o_31F.rst
 
b/Misc/NEWS.d/next/Core_and_Builtins/2026-06-08-05-31-22.gh-issue-151065._o_31F.rst
new file mode 100644
index 000000000000000..e46c96ef784cc9e
--- /dev/null
+++ 
b/Misc/NEWS.d/next/Core_and_Builtins/2026-06-08-05-31-22.gh-issue-151065._o_31F.rst
@@ -0,0 +1 @@
+Fix memory leak when using the :ref:`mimalloc memory allocator <mimalloc>`.
diff --git a/Objects/mimalloc/init.c b/Objects/mimalloc/init.c
index 81b241063ff40fc..7711c827a58b1ca 100644
--- a/Objects/mimalloc/init.c
+++ b/Objects/mimalloc/init.c
@@ -183,9 +183,9 @@ mi_heap_t* _mi_heap_main_get(void) {
 
 // note: in x64 in release build `sizeof(mi_thread_data_t)` is under 4KiB (= 
OS page size).
 typedef struct mi_thread_data_s {
-  mi_heap_t  heap;  // must come first due to cast in `_mi_heap_done`
+  mi_heap_t  heap;   // must come first due to cast in `_mi_heap_done`
   mi_tld_t   tld;
-  mi_memid_t memid;
+  mi_memid_t memid;  // must come last due to zero'ing
 } mi_thread_data_t;
 
 
@@ -231,7 +231,7 @@ static mi_thread_data_t* mi_thread_data_zalloc(void) {
   }
 
   if (td != NULL && !is_zero) {
-    _mi_memzero_aligned(td, sizeof(*td));
+    _mi_memzero_aligned(td, offsetof(mi_thread_data_t,memid));
   }
   return td;
 }

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to