From 2f0fd47bb49cf0324110fce67c0574542b0b7a55 Mon Sep 17 00:00:00 2001 From: Prakash Sellathurai Date: Wed, 24 Jun 2026 16:44:41 +0530 Subject: [PATCH] [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 00000000000000..c02145233d0e82 --- /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 467c3fe56e98f2..9d26a3cdeed4e7 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);