PyCodeObject *co = _PyFrame_GetCode(f->f_frame);
if (!(co->co_flags & CO_OPTIMIZED) && !_PyFrame_HasHiddenLocals(f->f_frame)) {
+ if (f->f_frame->f_locals == NULL) {
+ // We found cases when f_locals is NULL for non-optimized code.
+ // We fill the f_locals with an empty dict to avoid crash until
+ // we find the root cause.
+ f->f_frame->f_locals = PyDict_New();
+ if (f->f_frame->f_locals == NULL) {
+ return NULL;
+ }
+ }
return Py_NewRef(f->f_frame->f_locals);
}
PyCodeObject *co = _PyFrame_GetCode(frame);
if (!(co->co_flags & CO_OPTIMIZED) && !_PyFrame_HasHiddenLocals(frame)) {
+ if (frame->f_locals == NULL) {
+ // We found cases when f_locals is NULL for non-optimized code.
+ // We fill the f_locals with an empty dict to avoid crash until
+ // we find the root cause.
+ frame->f_locals = PyDict_New();
+ if (frame->f_locals == NULL) {
+ return NULL;
+ }
+ }
return Py_NewRef(frame->f_locals);
}