[issue40217] The garbage collector doesn't take in account that objects of heap allocated types hold a strong reference to their type
Pablo Galindo Salgado
report at bugs.python.org
Fri May 22 19:57:26 EDT 2020
Pablo Galindo Salgado <pablogsal at gmail.com> added the comment:
Ok, I found the problem. The problem is that the reproduced does not correctly work the reference count of base_class because when construction get tuple of bases:
PyObject *bases = PyTuple_New(1);
result = PyTuple_SetItem(bases, 0, base_class);
if (result) return -1;
PyObject *subclass = PyType_FromModuleAndSpec(m, &subclass_spec, bases);
"PyTuple_SetItem" steals a reference to base_class but "PyModule_AddObject" also does the same, and the refcount is incorrect.
If you add a Py_INCREF before, the crash disappears.
----------
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue40217>
_______________________________________
More information about the Python-bugs-list
mailing list