https://github.com/python/cpython/commit/e2a7db717507a66b49bb796391530147b3acab93
commit: e2a7db717507a66b49bb796391530147b3acab93
branch: main
author: Shamil <[email protected]>
committer: Fidget-Spinner <[email protected]>
date: 2025-12-19T19:07:11Z
summary:

gh-142476: fix memory leak when creating JIT executors (GH-142492)

files:
A 
Misc/NEWS.d/next/Core_and_Builtins/2025-12-13-01-11-03.gh-issue-142476.44Sp4N.rst
M 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
index 00000000000000..eae1f3a1ce53b6
--- /dev/null
+++ 
b/Misc/NEWS.d/next/Core_and_Builtins/2025-12-13-01-11-03.gh-issue-142476.44Sp4N.rst
@@ -0,0 +1,2 @@
+Fix a memory leak in the experimental Tier 2 optimizer when creating
+executors. Patched by Shamil Abdulaev.
diff --git a/Python/optimizer.c b/Python/optimizer.c
index 1e905850e3de6b..16abced6edbeec 100644
--- a/Python/optimizer.c
+++ b/Python/optimizer.c
@@ -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

_______________________________________________
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