[3.14] GH-140058: Clear key and value if PyTuple_New fails in dictiter_iternextitem (GH-140059) (#140107)

GH-140058: Clear key and value if `PyTuple_New` fails in `dictiter_iternextitem` (GH-140059)
(cherry picked from commit ded59f7e8e)

Co-authored-by: Sergey Miryanov <sergey.miryanov@gmail.com>
This commit is contained in:
Miss Islington (bot) 2025-10-14 15:40:30 +02:00 committed by GitHub
parent 45577c93de
commit 2142f4efcf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -5670,8 +5670,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);
}