gh-146092: Handle _PyFrame_GetFrameObject() failures properly (#146124)
* Fix _PyFrame_GetLocals() and _PyFrame_GetLocals() error handling.
* _PyEval_ExceptionGroupMatch() now fails on _PyFrame_GetLocals()
error.
(cherry picked from commit
e1e4852133ea548479bc9b975420a32331df7cee)
}
PyFrameObject* f = _PyFrame_GetFrameObject(frame);
+ if (f == NULL) {
+ return NULL;
+ }
return _PyFrameLocalsProxy_New(f);
}
return -1;
}
PyFrameObject *f = _PyFrame_GetFrameObject(frame);
- if (f != NULL) {
- PyObject *tb = _PyTraceBack_FromFrame(NULL, f);
- if (tb == NULL) {
- return -1;
- }
- PyException_SetTraceback(wrapped, tb);
- Py_DECREF(tb);
+ if (f == NULL) {
+ Py_DECREF(wrapped);
+ return -1;
+ }
+
+ PyObject *tb = _PyTraceBack_FromFrame(NULL, f);
+ if (tb == NULL) {
+ return -1;
}
+ PyException_SetTraceback(wrapped, tb);
+ Py_DECREF(tb);
*match = wrapped;
}
*rest = Py_NewRef(Py_None);
if (PyFrameLocalsProxy_Check(locals)) {
PyFrameObject *f = _PyFrame_GetFrameObject(current_frame);
+ if (f == NULL) {
+ Py_DECREF(locals);
+ return NULL;
+ }
+
PyObject *ret = f->f_locals_cache;
if (ret == NULL) {
ret = PyDict_New();