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

This commit is contained in:
Sergey Miryanov 2025-10-14 17:45:39 +05:00 committed by GitHub
parent 6ecf77dbde
commit ded59f7e8e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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);
}