slp_prepare_slots leaks memory #135
Description
slp_prepare_slots() called twice
The function slp_prepare_slots(PyTypeObject * type)
gets called from two places.
-
From
init_stackless_methods()
. Hereinit_stackless_methods()
sets Py_TPFLAGS_HAVE_STACKLESS_EXTENSION before calling slp_prepare_slots(). Everything is fine. -
From
inherit_slots()
intypeobject.c
by theCOPY*()
macros. These macros do not setPy_TPFLAGS_HAVE_STACKLESS_EXTENSION
. Thereforeslp_prepare_slots()
gets called
twice.
Fix: Set Py_TPFLAGS_HAVE_STACKLESS_EXTENSION only in slp_prepare_slots()
The allocated PyMappingMethods is never freed
No problem for static types, but it is a problem for heap types. We can free the memory in the tp_dealloc slot function of PyType_Type
(Python class type
). If Py_TPFLAGS_HAVE_STACKLESS_EXTENSION and Py_TPFLAGS_HEAPTYPE are set, tp_as_mapping
was allocated by slp_prepare_slots()