]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-151065: Copy fix for memory leak from mimalloc upstream (GH-151066)
authorPeter Bierma <zintensitydev@gmail.com>
Thu, 11 Jun 2026 22:11:52 +0000 (18:11 -0400)
committerGitHub <noreply@github.com>
Thu, 11 Jun 2026 22:11:52 +0000 (18:11 -0400)
Applies https://github.com/microsoft/mimalloc/commit/d7a72c4912943e8aaf135e465ca5ea229ea96646 to our copy of mimalloc.

Misc/NEWS.d/next/Core_and_Builtins/2026-06-08-05-31-22.gh-issue-151065._o_31F.rst [new file with mode: 0644]
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 (file)
index 0000000..e46c96e
--- /dev/null
@@ -0,0 +1 @@
+Fix memory leak when using the :ref:`mimalloc memory allocator <mimalloc>`.
index 81b241063ff40fcb2c71e8785ccd6c9b7b8cf4f8..7711c827a58b1ca2cb4c1bdf4638619c4e16a163 100644 (file)
@@ -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;
 }