]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.13] gh-141536: Fix a crash when running test_capi *after* test_code in the same...
authorStan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
Mon, 12 Jan 2026 18:07:34 +0000 (18:07 +0000)
committerGitHub <noreply@github.com>
Mon, 12 Jan 2026 18:07:34 +0000 (20:07 +0200)
(cherry picked from commit b2827de18fe88152dc38c1aa76c39b69ef59cb6f)

Co-authored-by: T. Wouters <thomas@python.org>
Lib/test/test_code.py

index 6f300a252dad45eda70695460b08af46b42dcd51..6ea6c486de53397e5ca85a21c8e9ee4a8a6f2060 100644 (file)
@@ -143,7 +143,7 @@ from test.support import (cpython_only,
                           check_impl_detail, requires_debug_ranges,
                           gc_collect, Py_GIL_DISABLED,
                           suppress_immortalization,
-                          skip_if_suppress_immortalization)
+                          skip_if_suppress_immortalization, 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
@@ -844,6 +844,11 @@ if check_impl_detail(cpython=True) and ctypes is not None:
 
     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):