]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.14] gh-151905: fix memory error handling in PyFrame_GetBack (GH-151906) (#151918)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Tue, 23 Jun 2026 13:46:54 +0000 (15:46 +0200)
committerGitHub <noreply@github.com>
Tue, 23 Jun 2026 13:46:54 +0000 (19:16 +0530)
gh-151905: fix memory error handling in PyFrame_GetBack (GH-151906)
(cherry picked from commit 1ab8862ea0ad8d52af8a75866077b1e09b0ba62d)

Co-authored-by: Prakash Sellathurai <prakashsellathurai@gmail.com>
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 51d3e6c8d3171983803751b4c26ecda9c75f1438..b4597a937074b8f59d463eea0fa32e5d7a13b89c 100644 (file)
@@ -1109,7 +1109,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;
@@ -2400,6 +2400,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);