From 117b76a19078e5454f2530e91cae5646eec7502c Mon Sep 17 00:00:00 2001 From: Prakash Sellathurai Date: Wed, 24 Jun 2026 17:10:07 +0530 Subject: [PATCH] [3.13] gh-151905: fix memory error handling in PyFrame_GetBack (GH-151906) (#152065) [3.13] gh-151905: fix memory error handling in PyFrame_GetBack (pythonGH-151906) Signed-off-by: Prakash Sellathurai --- .../2026-06-24-11-12-56.gh-issue-151905.j32skf.rst | 2 ++ Objects/frameobject.c | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 Misc/NEWS.d/next/Core_and_Builtins/2026-06-24-11-12-56.gh-issue-151905.j32skf.rst diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2026-06-24-11-12-56.gh-issue-151905.j32skf.rst b/Misc/NEWS.d/next/Core_and_Builtins/2026-06-24-11-12-56.gh-issue-151905.j32skf.rst new file mode 100644 index 000000000000..c02145233d0e --- /dev/null +++ b/Misc/NEWS.d/next/Core_and_Builtins/2026-06-24-11-12-56.gh-issue-151905.j32skf.rst @@ -0,0 +1,2 @@ +Fix OOM error handling in :c:func:`PyFrame_GetBack` to propagate exceptions +instead of masking them as None. diff --git a/Objects/frameobject.c b/Objects/frameobject.c index 467c3fe56e98..9d26a3cdeed4 100644 --- a/Objects/frameobject.c +++ b/Objects/frameobject.c @@ -963,7 +963,7 @@ static PyObject * frame_getback(PyFrameObject *f, void *closure) { PyObject *res = (PyObject *)PyFrame_GetBack(f); - if (res == NULL) { + if (res == NULL && !PyErr_Occurred()) { Py_RETURN_NONE; } return res; @@ -2203,6 +2203,9 @@ PyFrame_GetBack(PyFrameObject *frame) prev = _PyFrame_GetFirstComplete(prev); if (prev) { back = _PyFrame_GetFrameObject(prev); + if (back == NULL) { + return NULL; + } } } return (PyFrameObject*)Py_XNewRef(back); -- 2.47.3