Skip to content

Reference leak in code object with reference loop #148722

Description

@serhiy-storchaka

If the code object creates a reference loop, this causes a reference leak. For example (see :

def f():
    return 1234.5

code = f.__code__
a = []
code = code.replace(co_consts=code.co_consts + (a,))
a.append(code)

(See

def test_reference_loop_code(self):
def f():
return 1234.5
code = f.__code__
a = []
code = code.replace(co_consts=code.co_consts + (a,))
a.append(code)
added in #148698)

This is because in the GIL-enabled build the code object does not support GC and does not have tp_traverse.

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

    3.13bugs and security fixes3.14bugs and security fixes3.15pre-release feature fixes, bugs and security fixesinterpreter-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