Skip to content

Commit 72d5dfa

Browse files
[3.12] pythongh-104614: Fix potential ref. leak in _testcapimodule/get_basic_static_type() (pythonGH-105225) (python#105248)
(cherry picked from commit e01b04c) Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
1 parent 00fe618 commit 72d5dfa

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

Modules/_testcapimodule.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -2658,13 +2658,15 @@ get_basic_static_type(PyObject *self, PyObject *args)
26582658
PyTypeObject *cls = &BasicStaticTypes[num_basic_static_types_used++];
26592659

26602660
if (base != NULL) {
2661-
cls->tp_base = (PyTypeObject *)Py_NewRef(base);
26622661
cls->tp_bases = Py_BuildValue("(O)", base);
26632662
if (cls->tp_bases == NULL) {
26642663
return NULL;
26652664
}
2665+
cls->tp_base = (PyTypeObject *)Py_NewRef(base);
26662666
}
26672667
if (PyType_Ready(cls) < 0) {
2668+
Py_DECREF(cls->tp_bases);
2669+
Py_DECREF(cls->tp_base);
26682670
return NULL;
26692671
}
26702672
return (PyObject *)cls;

0 commit comments

Comments
 (0)