]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.13] GH-140058: Clear key and value if `PyTuple_New` fails in `dictiter_iternextite...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Tue, 14 Oct 2025 13:40:13 +0000 (15:40 +0200)
committerGitHub <noreply@github.com>
Tue, 14 Oct 2025 13:40:13 +0000 (13:40 +0000)
GH-140058: Clear key and value if `PyTuple_New` fails in `dictiter_iternextitem` (GH-140059)
(cherry picked from commit ded59f7e8e93274488584574ff2336a98bc4eff6)

Co-authored-by: Sergey Miryanov <sergey.miryanov@gmail.com>
Objects/dictobject.c

index 6937a140f1a396830e0b1e5c1712848018770721..3ab080b3e73449670058425ce826fb6e9928f13f 100644 (file)
@@ -5611,8 +5611,11 @@ dictiter_iternextitem(PyObject *self)
         }
         else {
             result = PyTuple_New(2);
-            if (result == NULL)
+            if (result == NULL) {
+                Py_DECREF(key);
+                Py_DECREF(value);
                 return NULL;
+            }
             PyTuple_SET_ITEM(result, 0, key);
             PyTuple_SET_ITEM(result, 1, value);
         }