mirror of
https://github.com/python/cpython.git
synced 2025-07-24 11:44:31 +00:00
GH-99729: Unlink frames before clearing them (GH-100030)
This commit is contained in:
parent
85d5a7e8ef
commit
b72014c783
6 changed files with 60 additions and 11 deletions
|
@ -619,7 +619,10 @@ dummy_func(
|
|||
DTRACE_FUNCTION_EXIT();
|
||||
_Py_LeaveRecursiveCallPy(tstate);
|
||||
assert(frame != &entry_frame);
|
||||
frame = cframe.current_frame = pop_frame(tstate, frame);
|
||||
// GH-99729: We need to unlink the frame *before* clearing it:
|
||||
_PyInterpreterFrame *dying = frame;
|
||||
frame = cframe.current_frame = dying->previous;
|
||||
_PyEvalFrameClearAndPop(tstate, dying);
|
||||
_PyFrame_StackPush(frame, retval);
|
||||
goto resume_frame;
|
||||
}
|
||||
|
|
|
@ -1009,14 +1009,6 @@ trace_function_exit(PyThreadState *tstate, _PyInterpreterFrame *frame, PyObject
|
|||
return 0;
|
||||
}
|
||||
|
||||
static _PyInterpreterFrame *
|
||||
pop_frame(PyThreadState *tstate, _PyInterpreterFrame *frame)
|
||||
{
|
||||
_PyInterpreterFrame *prev_frame = frame->previous;
|
||||
_PyEvalFrameClearAndPop(tstate, frame);
|
||||
return prev_frame;
|
||||
}
|
||||
|
||||
|
||||
int _Py_CheckRecursiveCallPy(
|
||||
PyThreadState *tstate)
|
||||
|
@ -1432,7 +1424,10 @@ exit_unwind:
|
|||
assert(_PyErr_Occurred(tstate));
|
||||
_Py_LeaveRecursiveCallPy(tstate);
|
||||
assert(frame != &entry_frame);
|
||||
frame = cframe.current_frame = pop_frame(tstate, frame);
|
||||
// GH-99729: We need to unlink the frame *before* clearing it:
|
||||
_PyInterpreterFrame *dying = frame;
|
||||
frame = cframe.current_frame = dying->previous;
|
||||
_PyEvalFrameClearAndPop(tstate, dying);
|
||||
if (frame == &entry_frame) {
|
||||
/* Restore previous cframe and exit */
|
||||
tstate->cframe = cframe.previous;
|
||||
|
|
|
@ -127,6 +127,9 @@ _PyFrame_Clear(_PyInterpreterFrame *frame)
|
|||
* to have cleared the enclosing generator, if any. */
|
||||
assert(frame->owner != FRAME_OWNED_BY_GENERATOR ||
|
||||
_PyFrame_GetGenerator(frame)->gi_frame_state == FRAME_CLEARED);
|
||||
// GH-99729: Clearing this frame can expose the stack (via finalizers). It's
|
||||
// crucial that this frame has been unlinked, and is no longer visible:
|
||||
assert(_PyThreadState_GET()->cframe->current_frame != frame);
|
||||
if (frame->frame_obj) {
|
||||
PyFrameObject *f = frame->frame_obj;
|
||||
frame->frame_obj = NULL;
|
||||
|
|
5
Python/generated_cases.c.h
generated
5
Python/generated_cases.c.h
generated
|
@ -628,7 +628,10 @@
|
|||
DTRACE_FUNCTION_EXIT();
|
||||
_Py_LeaveRecursiveCallPy(tstate);
|
||||
assert(frame != &entry_frame);
|
||||
frame = cframe.current_frame = pop_frame(tstate, frame);
|
||||
// GH-99729: We need to unlink the frame *before* clearing it:
|
||||
_PyInterpreterFrame *dying = frame;
|
||||
frame = cframe.current_frame = dying->previous;
|
||||
_PyEvalFrameClearAndPop(tstate, dying);
|
||||
_PyFrame_StackPush(frame, retval);
|
||||
goto resume_frame;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue