mirror of
https://github.com/python/cpython.git
synced 2026-04-14 15:50:50 +00:00
gh-146092: Handle _PyFrame_GetFrameObject() failures properly (#146124)
* Fix _PyFrame_GetLocals() and _PyFrame_GetLocals() error handling. * _PyEval_ExceptionGroupMatch() now fails on _PyFrame_GetLocals() error.
This commit is contained in:
parent
724c7c8146
commit
e1e4852133
2 changed files with 20 additions and 8 deletions
|
|
@ -2237,15 +2237,19 @@ _PyEval_ExceptionGroupMatch(_PyInterpreterFrame *frame, PyObject* exc_value,
|
|||
return -1;
|
||||
}
|
||||
PyFrameObject *f = _PyFrame_GetFrameObject(frame);
|
||||
if (f != NULL) {
|
||||
PyObject *tb = _PyTraceBack_FromFrame(NULL, f);
|
||||
if (tb == NULL) {
|
||||
Py_DECREF(wrapped);
|
||||
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) {
|
||||
Py_DECREF(wrapped);
|
||||
return -1;
|
||||
}
|
||||
PyException_SetTraceback(wrapped, tb);
|
||||
Py_DECREF(tb);
|
||||
|
||||
*match = wrapped;
|
||||
}
|
||||
*rest = Py_NewRef(Py_None);
|
||||
|
|
@ -2620,6 +2624,11 @@ PyEval_GetLocals(void)
|
|||
|
||||
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();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue