Skip to content

HAMT iterators are not tracked by GC and can leak #155515

Description

@nascheme

Bug report

Bug description:

The HAMT iterator types declare Py_TPFLAGS_HAVE_GC and implement tp_traverse, tp_clear and a tp_dealloc that untracks, but hamt_baseiter_new() never called PyObject_GC_Track(). A reference cycle running through an iterator -- iterator -> HAMT -> object -> iterator -- was therefore invisible to the collector and never freed. Because a contextvars.Context is backed by a HAMT that pins every object in it, one leaked iterator leaks the whole context.

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Linked PRs

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

    Labels

    interpreter-core(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions