fix refleaks in PyDict_SetItem error cases (closes #27248)

This commit is contained in:
Benjamin Peterson 2016-07-06 23:26:32 -07:00
parent a1fc45ae73
commit 27007dccec
1 changed files with 9 additions and 3 deletions

View File

@ -4509,8 +4509,10 @@ add_members(PyTypeObject *type, PyMemberDef *memb)
descr = PyDescr_NewMember(type, memb); descr = PyDescr_NewMember(type, memb);
if (descr == NULL) if (descr == NULL)
return -1; return -1;
if (PyDict_SetItemString(dict, memb->name, descr) < 0) if (PyDict_SetItemString(dict, memb->name, descr) < 0) {
Py_DECREF(descr);
return -1; return -1;
}
Py_DECREF(descr); Py_DECREF(descr);
} }
return 0; return 0;
@ -4529,8 +4531,10 @@ add_getset(PyTypeObject *type, PyGetSetDef *gsp)
if (descr == NULL) if (descr == NULL)
return -1; return -1;
if (PyDict_SetItemString(dict, gsp->name, descr) < 0) if (PyDict_SetItemString(dict, gsp->name, descr) < 0) {
Py_DECREF(descr);
return -1; return -1;
}
Py_DECREF(descr); Py_DECREF(descr);
} }
return 0; return 0;
@ -7010,8 +7014,10 @@ add_operators(PyTypeObject *type)
descr = PyDescr_NewWrapper(type, p, *ptr); descr = PyDescr_NewWrapper(type, p, *ptr);
if (descr == NULL) if (descr == NULL)
return -1; 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; return -1;
}
Py_DECREF(descr); Py_DECREF(descr);
} }
} }