]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.12] gh-104614: Fix potential ref. leak in _testcapimodule/get_basic_static_type...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Fri, 2 Jun 2023 17:09:51 +0000 (10:09 -0700)
committerGitHub <noreply@github.com>
Fri, 2 Jun 2023 17:09:51 +0000 (17:09 +0000)
(cherry picked from commit e01b04c9075c6468ed57bc883693ec2a06a6dd8e)

Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
Modules/_testcapimodule.c

index 3caaca35cd742daf7e085f07ab186098cc6a5784..b8ad00a019742199996ad4c8aee15f0f6d8b036b 100644 (file)
@@ -2658,13 +2658,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;