]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-151905: fix memory error handling in PyFrame_GetBack (#151906)
authorPrakash Sellathurai <prakashsellathurai@gmail.com>
Mon, 22 Jun 2026 11:11:31 +0000 (16:41 +0530)
committerGitHub <noreply@github.com>
Mon, 22 Jun 2026 11:11:31 +0000 (16:41 +0530)
Misc/NEWS.d/next/Core_and_Builtins/2026-06-22-06-26-34.gh-issue-151905.FOLMYg.rst [new file with mode: 0644]
Objects/frameobject.c

diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2026-06-22-06-26-34.gh-issue-151905.FOLMYg.rst b/Misc/NEWS.d/next/Core_and_Builtins/2026-06-22-06-26-34.gh-issue-151905.FOLMYg.rst
new file mode 100644 (file)
index 0000000..c71122d
--- /dev/null
@@ -0,0 +1 @@
+Fix OOM error handling in :c:func:`PyFrame_GetBack` to propagate exceptions instead of masking them as None.
index b19889d3034e7156b439e1e30d3314ccbe9dc1b9..e7ac59379dcfbcce95e162de2d3b4518eb81efd9 100644 (file)
@@ -1114,7 +1114,7 @@ frame_back_get_impl(PyFrameObject *self)
 /*[clinic end generated code: output=3a84c22a55a63c79 input=9e528570d0e1f44a]*/
 {
     PyObject *res = (PyObject *)PyFrame_GetBack(self);
-    if (res == NULL) {
+    if (res == NULL && !PyErr_Occurred()) {
         Py_RETURN_NONE;
     }
     return res;
@@ -2402,6 +2402,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);