@@ -1617,14 +1617,6 @@ trace_function_exit(PyThreadState *tstate, _PyInterpreterFrame *frame, PyObject
1617
1617
return 0 ;
1618
1618
}
1619
1619
1620
- static _PyInterpreterFrame *
1621
- pop_frame (PyThreadState * tstate , _PyInterpreterFrame * frame )
1622
- {
1623
- _PyInterpreterFrame * prev_frame = frame -> previous ;
1624
- _PyEvalFrameClearAndPop (tstate , frame );
1625
- return prev_frame ;
1626
- }
1627
-
1628
1620
/* It is only between the PRECALL instruction and the following CALL,
1629
1621
* that this has any meaning.
1630
1622
*/
@@ -2441,7 +2433,10 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
2441
2433
DTRACE_FUNCTION_EXIT ();
2442
2434
_Py_LeaveRecursiveCallTstate (tstate );
2443
2435
if (!frame -> is_entry ) {
2444
- frame = cframe .current_frame = pop_frame (tstate , frame );
2436
+ // GH-99729: We need to unlink the frame *before* clearing it:
2437
+ _PyInterpreterFrame * dying = frame ;
2438
+ frame = cframe .current_frame = dying -> previous ;
2439
+ _PyEvalFrameClearAndPop (tstate , dying );
2445
2440
_PyFrame_StackPush (frame , retval );
2446
2441
goto resume_frame ;
2447
2442
}
@@ -5833,7 +5828,10 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
5833
5828
assert (tstate -> cframe -> current_frame == frame -> previous );
5834
5829
return NULL ;
5835
5830
}
5836
- frame = cframe .current_frame = pop_frame (tstate , frame );
5831
+ // GH-99729: We need to unlink the frame *before* clearing it:
5832
+ _PyInterpreterFrame * dying = frame ;
5833
+ frame = cframe .current_frame = dying -> previous ;
5834
+ _PyEvalFrameClearAndPop (tstate , dying );
5837
5835
5838
5836
resume_with_error :
5839
5837
SET_LOCALS_FROM_FRAME ();
0 commit comments