GH-93990: fix refcounting bug in `add_subclass` in `typeobject.c` (GH-93989)

This commit is contained in:
Kumar Aditya 2022-06-19 11:36:37 +05:30 committed by GitHub
parent 6066f450b9
commit 726448ebe1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 1 deletions

View File

@ -6671,9 +6671,12 @@ add_subclass(PyTypeObject *base, PyTypeObject *type)
PyObject *subclasses = base->tp_subclasses;
if (subclasses == NULL) {
base->tp_subclasses = subclasses = PyDict_New();
if (subclasses == NULL)
if (subclasses == NULL) {
Py_DECREF(key);
Py_DECREF(ref);
return -1;
}
}
assert(PyDict_CheckExact(subclasses));
int result = PyDict_SetItem(subclasses, key, ref);