https://github.com/python/cpython/commit/bf3ed370de0cf0f070871b48d9f0f7652acc1fc3
commit: bf3ed370de0cf0f070871b48d9f0f7652acc1fc3
branch: 3.14
author: Miss Islington (bot) <[email protected]>
committer: kumaraditya303 <[email protected]>
date: 2026-01-10T12:24:04+05:30
summary:

[3.14] gh-141536: Fix a crash when running test_capi *after* test_code in the 
same process (GH-141537) (#143522)

gh-141536: Fix a crash when running test_capi *after* test_code in the same 
process (GH-141537)
(cherry picked from commit b2827de18fe88152dc38c1aa76c39b69ef59cb6f)

Co-authored-by: T. Wouters <[email protected]>

files:
M Lib/test/test_code.py

diff --git a/Lib/test/test_code.py b/Lib/test/test_code.py
index 655f5a9be7fa31..0d5c6e6e77f5d7 100644
--- a/Lib/test/test_code.py
+++ b/Lib/test/test_code.py
@@ -210,7 +210,7 @@
     ctypes = None
 from test.support import (cpython_only,
                           check_impl_detail, requires_debug_ranges,
-                          gc_collect, Py_GIL_DISABLED)
+                          gc_collect, Py_GIL_DISABLED, late_deletion)
 from test.support.script_helper import assert_python_ok
 from test.support import threading_helper, import_helper
 from test.support.bytecode_helper import instructions_with_positions
@@ -1555,6 +1555,11 @@ def myfree(ptr):
 
     FREE_FUNC = freefunc(myfree)
     FREE_INDEX = RequestCodeExtraIndex(FREE_FUNC)
+    # Make sure myfree sticks around at least as long as the interpreter,
+    # since we (currently) can't unregister the function and leaving a
+    # dangling pointer will cause a crash on deallocation of code objects if
+    # something else uses co_extras, like test_capi.test_misc.
+    late_deletion(myfree)
 
     class CoExtra(unittest.TestCase):
         def get_func(self):

_______________________________________________
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