From beba1020a9d5b0350185b42fef6314cbe6c1d071 Mon Sep 17 00:00:00 2001 From: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com> Date: Sun, 19 Jun 2022 16:56:13 +0530 Subject: [PATCH] GH-93990: fix refcounting bug in `add_subclass` in `typeobject.c` (GH-93989) (GH-93999) (cherry picked from commit 726448ebe15cd78e180c29c9858cb6c10a581524) --- Objects/typeobject.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Objects/typeobject.c b/Objects/typeobject.c index 50f2742f676f68..65a9475ab7d7fe 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -6400,8 +6400,11 @@ add_subclass(PyTypeObject *base, PyTypeObject *type) PyObject *dict = base->tp_subclasses; if (dict == NULL) { base->tp_subclasses = dict = PyDict_New(); - if (dict == NULL) + if (dict == NULL) { + Py_DECREF(key); + Py_DECREF(ref); return -1; + } } assert(PyDict_CheckExact(dict));