]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-142476: fix memory leak when creating JIT executors (GH-142492)
authorShamil <ashm.tech@proton.me>
Fri, 19 Dec 2025 19:07:11 +0000 (22:07 +0300)
committerGitHub <noreply@github.com>
Fri, 19 Dec 2025 19:07:11 +0000 (19:07 +0000)
Misc/NEWS.d/next/Core_and_Builtins/2025-12-13-01-11-03.gh-issue-142476.44Sp4N.rst [new file with mode: 0644]
Python/optimizer.c

diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2025-12-13-01-11-03.gh-issue-142476.44Sp4N.rst b/Misc/NEWS.d/next/Core_and_Builtins/2025-12-13-01-11-03.gh-issue-142476.44Sp4N.rst
new file mode 100644 (file)
index 0000000..eae1f3a
--- /dev/null
@@ -0,0 +1,2 @@
+Fix a memory leak in the experimental Tier 2 optimizer when creating
+executors. Patched by Shamil Abdulaev.
index 1e905850e3de6bffd85d0155eb9aa14847a71a59..16abced6edbeeca77400179613ad26eb88074247 100644 (file)
@@ -185,12 +185,17 @@ _PyOptimizer_Optimize(
     else {
         executor->vm_data.code = NULL;
     }
+    executor->vm_data.chain_depth = chain_depth;
+    assert(executor->vm_data.valid);
     _PyExitData *exit = _tstate->jit_tracer_state.initial_state.exit;
     if (exit != NULL) {
         exit->executor = executor;
     }
-    executor->vm_data.chain_depth = chain_depth;
-    assert(executor->vm_data.valid);
+    else {
+        // An executor inserted into the code object now has a strong reference
+        // to it from the code object. Thus, we don't need this reference anymore.
+        Py_DECREF(executor);
+    }
     interp->compiling = false;
     return 1;
 #else