From 544531de23d69f5b23883794fc7bb23a958a0fcb Mon Sep 17 00:00:00 2001 From: Mark Shannon Date: Fri, 1 Jul 2022 11:08:20 +0100 Subject: GH-94262: Don't create frame objects for frames that aren't yet complete. (GH-94371) --- Python/sysmodule.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'Python/sysmodule.c') diff --git a/Python/sysmodule.c b/Python/sysmodule.c index 444042f82d9..93120071b40 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -1776,9 +1776,17 @@ sys__getframe_impl(PyObject *module, int depth) return NULL; } - while (depth > 0 && frame != NULL) { - frame = frame->previous; - --depth; + if (frame != NULL) { + while (depth > 0) { + frame = frame->previous; + if (frame == NULL) { + break; + } + if (_PyFrame_IsIncomplete(frame)) { + continue; + } + --depth; + } } if (frame == NULL) { _PyErr_SetString(tstate, PyExc_ValueError, -- cgit v1.2.3