Skip to content

Commit e2a7db7

Browse files
authored
gh-142476: fix memory leak when creating JIT executors (GH-142492)
1 parent 6b4bc6e commit e2a7db7

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix a memory leak in the experimental Tier 2 optimizer when creating
2+
executors. Patched by Shamil Abdulaev.

Python/optimizer.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,12 +185,17 @@ _PyOptimizer_Optimize(
185185
else {
186186
executor->vm_data.code = NULL;
187187
}
188+
executor->vm_data.chain_depth = chain_depth;
189+
assert(executor->vm_data.valid);
188190
_PyExitData *exit = _tstate->jit_tracer_state.initial_state.exit;
189191
if (exit != NULL) {
190192
exit->executor = executor;
191193
}
192-
executor->vm_data.chain_depth = chain_depth;
193-
assert(executor->vm_data.valid);
194+
else {
195+
// An executor inserted into the code object now has a strong reference
196+
// to it from the code object. Thus, we don't need this reference anymore.
197+
Py_DECREF(executor);
198+
}
194199
interp->compiling = false;
195200
return 1;
196201
#else

0 commit comments

Comments
 (0)