Skip to content
This repository was archived by the owner on Feb 13, 2025. It is now read-only.
This repository was archived by the owner on Feb 13, 2025. It is now read-only.

slp_prepare_slots leaks memory #135

Description

@akruis

slp_prepare_slots() called twice

The function slp_prepare_slots(PyTypeObject * type) gets called from two places.

  1. From init_stackless_methods(). Here init_stackless_methods() sets Py_TPFLAGS_HAVE_STACKLESS_EXTENSION before calling slp_prepare_slots(). Everything is fine.

  2. From inherit_slots() in typeobject.c by the COPY*() macros. These macros do not set Py_TPFLAGS_HAVE_STACKLESS_EXTENSION. Therefore slp_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()

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions