Skip to content

Commit

Permalink
Fix crash in getlocals
Browse files Browse the repository at this point in the history
  • Loading branch information
gaogaotiantian committed May 7, 2024
1 parent b9caa09 commit c5bee13
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions Objects/frameobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -742,6 +742,15 @@ frame_getlocals(PyFrameObject *f, void *closure)
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);
}

Expand Down

0 comments on commit c5bee13

Please sign in to comment.