From: Shamil Date: Fri, 19 Dec 2025 19:07:11 +0000 (+0300) Subject: gh-142476: fix memory leak when creating JIT executors (GH-142492) X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e2a7db717507a66b49bb796391530147b3acab93;p=thirdparty%2FPython%2Fcpython.git gh-142476: fix memory leak when creating JIT executors (GH-142492) --- 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 000000000000..eae1f3a1ce53 --- /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 1e905850e3de..16abced6edbe 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