diff --git a/Objects/typeobject.c b/Objects/typeobject.c index c1bae0b9a6d62f..d95b850699ed8e 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -6512,8 +6512,11 @@ 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));