Skip to content

_posix_listdir may leak FD #62532

Closed
Closed

Description

@tiran
BPO 18332
Nosy @tiran
Superseder
  • bpo-17899: os.listdir() leaks FDs if invoked on FD pointing to a non-directory
  • 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 2013-06-30.17:43:23.825>
    created_at = <Date 2013-06-30.16:47:57.249>
    labels = ['extension-modules', 'performance']
    title = '_posix_listdir may leak FD'
    updated_at = <Date 2013-06-30.17:43:23.824>
    user = 'https://github.com/tiran'

    bugs.python.org fields:

    activity = <Date 2013-06-30.17:43:23.824>
    actor = 'christian.heimes'
    assignee = 'none'
    closed = True
    closed_date = <Date 2013-06-30.17:43:23.825>
    closer = 'christian.heimes'
    components = ['Extension Modules']
    creation = <Date 2013-06-30.16:47:57.249>
    creator = 'christian.heimes'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 18332
    keywords = []
    message_count = 3.0
    messages = ['192077', '192080', '192082']
    nosy_count = 2.0
    nosy_names = ['christian.heimes', 'sbt']
    pr_nums = []
    priority = 'normal'
    resolution = 'duplicate'
    stage = 'needs patch'
    status = 'closed'
    superseder = '17899'
    type = 'resource usage'
    url = 'https://bugs.python.org/issue18332'
    versions = ['Python 3.3', 'Python 3.4']

    Activity

    1. tiran commented on Jun 30, 2013

      @tiran
      MemberAuthor

      Under rare circumstances listdir() could leak a FD:

      • HAVE_FDOPENDIR is defined
      • dup(fd) succeeds
      • fdopendir() fails and sets dirp to NULL
      • if (dirp == NULL) goto exit
      • the dupped fd isn't closed because exit just handles dirp != NULL.

      Proposed fix:

          if (dirp != NULL) {
              ...
          } else if (fd != -1) {
              close(fd);
          }

      CID 992693 (#1 of 1): Resource leak (RESOURCE_LEAK)
      leaked_handle: Handle variable "fd" going out of scope leaks the handle

    2. added
      extension-modules
      performance
      on Jun 30, 2013
    3. sbt commented on Jun 30, 2013

      sbtmannequin
      Mannequin

      I think this is a duplicate of bpo-17899.

    4. tiran commented on Jun 30, 2013

      @tiran
      MemberAuthor

      You are right.

    5. 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

      extension-modulesperformance

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions