diff --git a/Objects/typeobject.c b/Objects/typeobject.c index 317334f739a..8c5c77e48e3 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -4509,8 +4509,10 @@ add_members(PyTypeObject *type, PyMemberDef *memb) descr = PyDescr_NewMember(type, memb); if (descr == NULL) return -1; - if (PyDict_SetItemString(dict, memb->name, descr) < 0) + if (PyDict_SetItemString(dict, memb->name, descr) < 0) { + Py_DECREF(descr); return -1; + } Py_DECREF(descr); } return 0; @@ -4529,8 +4531,10 @@ add_getset(PyTypeObject *type, PyGetSetDef *gsp) if (descr == NULL) return -1; - if (PyDict_SetItemString(dict, gsp->name, descr) < 0) + if (PyDict_SetItemString(dict, gsp->name, descr) < 0) { + Py_DECREF(descr); return -1; + } Py_DECREF(descr); } return 0; @@ -7010,8 +7014,10 @@ add_operators(PyTypeObject *type) descr = PyDescr_NewWrapper(type, p, *ptr); if (descr == NULL) return -1; - if (PyDict_SetItem(dict, p->name_strobj, descr) < 0) + if (PyDict_SetItem(dict, p->name_strobj, descr) < 0) { + Py_DECREF(descr); return -1; + } Py_DECREF(descr); } }