From 93c4b4797960730799cdc080f643ae80aa011400 Mon Sep 17 00:00:00 2001 From: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com> Date: Sat, 18 Jun 2022 17:00:37 +0000 Subject: [PATCH] fix refcounting bug --- Objects/typeobject.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Objects/typeobject.c b/Objects/typeobject.c index 513055168062f1..1236acdcd1930b 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -6671,8 +6671,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));