From: Sergey Miryanov Date: Tue, 14 Oct 2025 12:45:39 +0000 (+0500) Subject: GH-140058: Clear key and value if `PyTuple_New` fails in `dictiter_iternextitem`... X-Git-Tag: v3.15.0a2~448^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ded59f7e8e93274488584574ff2336a98bc4eff6;p=thirdparty%2FPython%2Fcpython.git GH-140058: Clear key and value if `PyTuple_New` fails in `dictiter_iternextitem` (#140059) --- diff --git a/Objects/dictobject.c b/Objects/dictobject.c index ddf9bde63f31..b95a4a8dc5ef 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); }