]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-104614: Fix potential ref. leak in _testcapimodule/get_basic_static_type() (#105225)
authorErlend E. Aasland <erlend.aasland@protonmail.com>
Fri, 2 Jun 2023 16:44:24 +0000 (18:44 +0200)
committerGitHub <noreply@github.com>
Fri, 2 Jun 2023 16:44:24 +0000 (18:44 +0200)
Modules/_testcapimodule.c

index 38c2d1a91af31c02d92a24b8136a4cd6e801e7b7..3acc7575cfe8dbd3ab37bb3ac0aafcaf89d35864 100644 (file)
@@ -2671,13 +2671,15 @@ get_basic_static_type(PyObject *self, PyObject *args)
     PyTypeObject *cls = &BasicStaticTypes[num_basic_static_types_used++];
 
     if (base != NULL) {
-        cls->tp_base = (PyTypeObject *)Py_NewRef(base);
         cls->tp_bases = Py_BuildValue("(O)", base);
         if (cls->tp_bases == NULL) {
             return NULL;
         }
+        cls->tp_base = (PyTypeObject *)Py_NewRef(base);
     }
     if (PyType_Ready(cls) < 0) {
+        Py_DECREF(cls->tp_bases);
+        Py_DECREF(cls->tp_base);
         return NULL;
     }
     return (PyObject *)cls;