diff --git a/Objects/typeobject.c b/Objects/typeobject.c index 78d5c1ee516..d42054a7f14 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -2580,8 +2580,10 @@ type_new(PyTypeObject *metatype, PyObject *args, PyObject *kwds) tmp = PyStaticMethod_New(tmp); if (tmp == NULL) goto error; - if (_PyDict_SetItemId(dict, &PyId___new__, tmp) < 0) + if (_PyDict_SetItemId(dict, &PyId___new__, tmp) < 0) { + Py_DECREF(tmp); goto error; + } Py_DECREF(tmp); }