[Python-checkins] GH-93990: fix refcounting bug in `add_subclass` in `typeobject.c` (GH-93989) (GH-93999)

Fidget-Spinner webhook-mailer at python.org
Sun Jun 19 07:26:17 EDT 2022


https://github.com/python/cpython/commit/beba1020a9d5b0350185b42fef6314cbe6c1d071
commit: beba1020a9d5b0350185b42fef6314cbe6c1d071
branch: 3.10
author: Kumar Aditya <59607654+kumaraditya303 at users.noreply.github.com>
committer: Fidget-Spinner <kenjin at python.org>
date: 2022-06-19T19:26:13+08:00
summary:

GH-93990: fix refcounting bug in `add_subclass` in `typeobject.c` (GH-93989) (GH-93999)

(cherry picked from commit 726448ebe15cd78e180c29c9858cb6c10a581524)

files:
M Objects/typeobject.c

diff --git a/Objects/typeobject.c b/Objects/typeobject.c
index 50f2742f676f6..65a9475ab7d7f 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));
 



More information about the Python-checkins mailing list