Skip to content

internals::tstate is leaked #2133

Closed
Closed
@bkloster-sma

Description

@bkloster-sma

Issue description

The Py_tss_t* internals::tstate created in get_internals() with PyThread_tss_create() is never released with PyThread_tss_delete(). This is usually not a problem, unless you happen to initialize an interpreter in a loop repeatedly. Eventually, the PyThread_tss_create() will fail (on Windows, because TlsAlloc() returns TLS_OUT_OF_INDEXES), causing get_internals() to throw an exception with the message "get_internals: could not successfully initialize the TSS key!".

On my machine, this happens when initializing the interpreter for the 1070th time.

Reproducible example code

while (true) {
    pybind11::initialize_interpreter();
    pybind11::finalize_interpreter();
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions