From 15c8838273e1be94dc3f32db21a35f5302ed1a1d Mon Sep 17 00:00:00 2001 From: "Miss Islington (bot)" <31488909+miss-islington@users.noreply.github.com> Date: Sun, 19 Jun 2022 02:51:22 -0700 Subject: [PATCH] GH-93990: fix refcounting bug in `add_subclass` in `typeobject.c` (GH-93989) (cherry picked from commit 726448ebe15cd78e180c29c9858cb6c10a581524) Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com> --- Objects/typeobject.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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));