From 7992a295123489f1b31b8b5724f02188cbe32e51 Mon Sep 17 00:00:00 2001 From: "Miss Islington (bot)" <31488909+miss-islington@users.noreply.github.com> Date: Tue, 14 Oct 2025 15:40:13 +0200 Subject: [PATCH] [3.13] GH-140058: Clear key and value if `PyTuple_New` fails in `dictiter_iternextitem` (GH-140059) (#140108) 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 --- Objects/dictobject.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Objects/dictobject.c b/Objects/dictobject.c index 6937a140f1a3..3ab080b3e734 100644 --- a/Objects/dictobject.c +++ b/Objects/dictobject.c @@ -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); } -- 2.47.3