Fix crash accessing PyEval_GetFrame from Python's crash handler

Check the thread-state before accessing PyEval_GetFrame, since this is
a crash handler, the state of the Python interpreter isn't known.
This commit is contained in:
Campbell Barton 2022-08-19 16:20:20 +10:00
parent 529f0427fc
commit 5c9bea25d0
1 changed files with 5 additions and 0 deletions

View File

@ -585,6 +585,11 @@ void BPY_python_use_system_env(void)
void BPY_python_backtrace(FILE *fp)
{
fputs("\n# Python backtrace\n", fp);
/* Can happen in rare cases. */
if (!_PyThreadState_UncheckedGet()) {
return;
}
PyFrameObject *frame;
if (!(frame = PyEval_GetFrame())) {
return;