]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-108727: Fix segfault due to missing tp_dealloc definition for CounterOptimizer_Typ...
authorIrit Katriel <1055913+iritkatriel@users.noreply.github.com>
Fri, 1 Sep 2023 09:16:09 +0000 (10:16 +0100)
committerGitHub <noreply@github.com>
Fri, 1 Sep 2023 09:16:09 +0000 (10:16 +0100)
Lib/test/test_capi/test_misc.py
Misc/NEWS.d/next/Core and Builtins/2023-08-31-21-29-28.gh-issue-108727.blNRGM.rst [new file with mode: 0644]
Python/optimizer.c

index 4148f15b2aa662460046e020ce093429d56a4360..004ce3976965568e032cf7e1c605ef2ca48f3ce8 100644 (file)
@@ -2284,6 +2284,13 @@ def clear_executors(func):
 
 class TestOptimizerAPI(unittest.TestCase):
 
+    def test_get_counter_optimizer_dealloc(self):
+        # See gh-108727
+        def f():
+            _testinternalcapi.get_counter_optimizer()
+
+        f()
+
     def test_get_set_optimizer(self):
         old = _testinternalcapi.get_optimizer()
         opt = _testinternalcapi.get_counter_optimizer()
diff --git a/Misc/NEWS.d/next/Core and Builtins/2023-08-31-21-29-28.gh-issue-108727.blNRGM.rst b/Misc/NEWS.d/next/Core and Builtins/2023-08-31-21-29-28.gh-issue-108727.blNRGM.rst
new file mode 100644 (file)
index 0000000..34959ae
--- /dev/null
@@ -0,0 +1,2 @@
+Define ``tp_dealloc`` for ``CounterOptimizer_Type``. This fixes a segfault
+on deallocation.
index c311a03fa59a2f7014fd2a1abc7ecc3ca5ec4d7a..7472f52c50b7668df6fabd7e98e74d7babc7871e 100644 (file)
@@ -289,6 +289,7 @@ static PyTypeObject CounterOptimizer_Type = {
     .tp_itemsize = 0,
     .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_DISALLOW_INSTANTIATION,
     .tp_methods = counter_methods,
+    .tp_dealloc = (destructor)PyObject_Del,
 };
 
 PyObject *