From 009ee96dff4be568f4c944ae4cadece830c08da3 Mon Sep 17 00:00:00 2001 From: Sergey Miryanov Date: Mon, 13 Oct 2025 19:26:23 +0500 Subject: [PATCH] Clear key and value if PyTuple_New fails in dictiter_iternextitem --- Objects/dictobject.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Objects/dictobject.c b/Objects/dictobject.c index ddf9bde63f31bb..b95a4a8dc5efec 100644 --- a/Objects/dictobject.c +++ b/Objects/dictobject.c @@ -5719,8 +5719,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); }