Skip to content

Reference leak with custom tp_dealloc in PyType_FromSpec #60894

Closed

Description

@bfroehle
mannequin
BPO 16690
Nosy @loewis, @ncoghlan, @pitrou, @encukou
Files
  • heaptype_refcnt_testcases.py
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2019-09-12.14:43:43.606>
    created_at = <Date 2012-12-15.01:39:25.523>
    labels = ['interpreter-core', 'performance']
    title = 'Reference leak with custom tp_dealloc in PyType_FromSpec'
    updated_at = <Date 2019-09-12.14:43:43.605>
    user = 'https://bugs.python.org/bfroehle'

    bugs.python.org fields:

    activity = <Date 2019-09-12.14:43:43.605>
    actor = 'petr.viktorin'
    assignee = 'none'
    closed = True
    closed_date = <Date 2019-09-12.14:43:43.606>
    closer = 'petr.viktorin'
    components = ['Interpreter Core']
    creation = <Date 2012-12-15.01:39:25.523>
    creator = 'bfroehle'
    dependencies = []
    files = ['28372']
    hgrepos = []
    issue_num = 16690
    keywords = []
    message_count = 6.0
    messages = ['177527', '177528', '177794', '244420', '244814', '352187']
    nosy_count = 7.0
    nosy_names = ['loewis', 'ncoghlan', 'pitrou', 'petr.viktorin', 'python-dev', 'Robin.Schreiber', 'bfroehle']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'resource usage'
    url = 'https://bugs.python.org/issue16690'
    versions = ['Python 3.2', 'Python 3.3', 'Python 3.4']

    Activity

    1. bfroehle commented on Dec 15, 2012

      bfroehlemannequin
      MannequinAuthor

      There is a reference leak when using PyType_FromSpec with custom tp_dealloc. This was first noted in issue bpo-15142, where a fix was given which only applies to types which do not override tp_dealloc.

      For example, the xxlimited.Xxo type suffers from this:

      Python 3.3.0 (default, Oct 26 2012, 11:06:17) 
      [GCC 4.6.3] on linux
      Type "help", "copyright", "credits" or "license" for more information.
      >>> import xxlimited
      >>> import sys
      >>> Xxo = type(xxlimited.new())
      >>> e = Xxo()
      >>> sys.getrefcount(Xxo)
      7
      >>> e = Xxo()
      >>> sys.getrefcount(Xxo)
      8
      >>> e = Xxo()
      >>> sys.getrefcount(Xxo)
      9
    2. bfroehle commented on Dec 15, 2012

      bfroehlemannequin
      MannequinAuthor

      I see this issue came up in the course of bpo-15653 as well.

    3. bfroehle commented on Dec 20, 2012

      bfroehlemannequin
      MannequinAuthor

      The attached file heaptype_refcnt_testcases.py runs through several test cases (ssl.SSLError, a subclass of ssl.SSLError, and xxlimited.Xxo) seeing if references are leaked in each instance.

      Unfortunately xxlimited.Xxo isn't set to be a base type and I don't know of any other types in the default install which use PyType_FromSpec with a custom tp_dealloc.

    4. ncoghlan commented on May 29, 2015

      @ncoghlan
      Contributor

      The new test cases for PEP-489 (multi-phase extension module import) appear to be encountering this leak.

      See bpo-24268 for context.

    5. python-dev commented on Jun 4, 2015

      python-devmannequin
      Mannequin

      New changeset 265eeb60443a by Nick Coghlan in branch '3.5':
      Issue bpo-24373: Eliminate PEP-489 test refleaks
      https://hg.python.org/cpython/rev/265eeb60443a

    6. encukou commented on Sep 12, 2019

      @encukou
      Member

      This is fixed in Python 3.5+.

    7. transferred this issue fromon Apr 10, 2022
    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)performancePerformance or resource usage

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions