Skip to content

Commit 11cdbd9

Browse files
Fix memory leak
1 parent e45ab76 commit 11cdbd9

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

Python/ceval.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1475,7 +1475,7 @@ stop_tracing_and_jit(PyThreadState *tstate, _PyInterpreterFrame *frame)
14751475
tracer->initial_state.jump_backward_instr[1].counter = initial_jump_backoff_counter(&_tstate->policy);
14761476
}
14771477
}
1478-
else {
1478+
else if (tracer->initial_state.executor->vm_data.valid) {
14791479
// Likewise, we hold a strong reference to the executor containing this exit, so the exit is guaranteed
14801480
// to be valid to access.
14811481
if (err <= 0) {

Python/optimizer.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,12 @@ _PyOptimizer_Optimize(
138138
// return immediately without optimization.
139139
return 0;
140140
}
141+
_PyExecutorObject *prev_executor = _tstate->jit_tracer_state->initial_state.executor;
142+
if (prev_executor != NULL && !prev_executor->vm_data.valid) {
143+
// gh-143604: If we are a side exit executor and the original executor is no
144+
// longer valid, don't compile to prevent a reference leak.
145+
return 0;
146+
}
141147
assert(!interp->compiling);
142148
assert(_tstate->jit_tracer_state->initial_state.stack_depth >= 0);
143149
#ifndef Py_GIL_DISABLED
@@ -1390,7 +1396,7 @@ make_executor_from_uops(_PyThreadStateImpl *tstate, _PyUOpInstruction *buffer, i
13901396
lltrace = *python_lltrace - '0'; // TODO: Parse an int and all that
13911397
}
13921398
if (lltrace >= 2) {
1393-
printf("Optimized trace (length %d):\n", length);
1399+
printf("Optimized trace (length %d) %d:\n", length, Py_SIZE((PyObject *)executor));
13941400
for (int i = 0; i < length; i++) {
13951401
printf("%4d OPTIMIZED: ", i);
13961402
_PyUOpPrint(&executor->trace[i]);

0 commit comments

Comments
 (0)