https://github.com/python/cpython/commit/4bb96fc2394ab47cf94e758d08f978742f64d26f
commit: 4bb96fc2394ab47cf94e758d08f978742f64d26f
branch: 3.15
author: Miss Islington (bot) <[email protected]>
committer: JelleZijlstra <[email protected]>
date: 2026-10-21T11:53:05-07:00
summary:

[3.15] gh-159739: Avoid destroying a remote unwinder cache twice (GH-159982) 
(#160023)



In a free-threaded build, if allocating the thread-local bytecode cache fails 
after the code-object cache has been created, the initializer destroys the 
first cache and returns an error without clearing its pointer. Failed 
construction then invokes the unwinder's deallocator, which destroys the same 
cache again and can crash the profiling process instead of propagating 
`MemoryError`.
(cherry picked from commit b577a5403ad513e6f28ec28630b5ee09a5f521ab)

Co-authored-by: Jelle Zijlstra <[email protected]>

files:
A Misc/NEWS.d/next/Library/2026-10-20-00-00-00.gh-issue-159739.5d4269.rst
M Modules/_remote_debugging/module.c

diff --git 
a/Misc/NEWS.d/next/Library/2026-10-20-00-00-00.gh-issue-159739.5d4269.rst 
b/Misc/NEWS.d/next/Library/2026-10-20-00-00-00.gh-issue-159739.5d4269.rst
new file mode 100644
index 000000000000000..94ee3cf4790112d
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2026-10-20-00-00-00.gh-issue-159739.5d4269.rst
@@ -0,0 +1 @@
+Fix a double free if remote unwinder initialization runs out of memory.
diff --git a/Modules/_remote_debugging/module.c 
b/Modules/_remote_debugging/module.c
index 03b398eb248e8fd..4a93b25b2bc2f85 100644
--- a/Modules/_remote_debugging/module.c
+++ b/Modules/_remote_debugging/module.c
@@ -450,7 +450,6 @@ 
_remote_debugging_RemoteUnwinder___init___impl(RemoteUnwinderObject *self,
         NULL
     );
     if (self->tlbc_cache == NULL) {
-        _Py_hashtable_destroy(self->code_object_cache);
         PyErr_NoMemory();
         set_exception_cause(self, PyExc_MemoryError, "Failed to create TLBC 
cache");
         return -1;

_______________________________________________
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