classification
Title: _posix_listdir may leak FD
Type: resource usage Stage: needs patch
Components: Extension Modules Versions: Python 3.3, Python 3.4
process
Status: closed Resolution: duplicate
Dependencies: Superseder: os.listdir() leaks FDs if invoked on FD pointing to a non-directory
View: 17899
Assigned To: Nosy List: christian.heimes, sbt
Priority: normal Keywords:

Created on 2013-06-30 16:47 by christian.heimes, last changed 2013-06-30 17:43 by christian.heimes. This issue is now closed.

Messages (3)
msg192077 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2013-06-30 16:47
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
msg192080 - (view) Author: Richard Oudkerk (sbt) * (Python committer) Date: 2013-06-30 17:26
I think this is a duplicate of #17899.
msg192082 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2013-06-30 17:43
You are right.
History
Date User Action Args
2013-06-30 17:43:23christian.heimessetstatus: open -> closed
superseder: os.listdir() leaks FDs if invoked on FD pointing to a non-directory
resolution: duplicate
messages: + msg192082
2013-06-30 17:26:50sbtsetnosy: + sbt
messages: + msg192080
2013-06-30 16:47:57christian.heimescreate