[issue17899] os.listdir() leaks FDs if invoked on FD pointing to a non-directory

Serhiy Storchaka report at bugs.python.org
Mon Jun 10 07:53:38 CEST 2013


Serhiy Storchaka added the comment:

rewinddir() is called only when dirp != NULL && fd > -1. fdopendir() is called when fd != -1. close() is called when dirp == NULL && fd != -1. Therefore rewinddir() and fdopendir() with close() can't be called in the same time. And you can move block

    if (dirp == NULL)
        close(fd);

up, just after fdopendir(). In all other branches fd == -1 and close() is not called. You will save #ifdef HAVE_FDOPENDIR/#endif and Py_BEGIN_ALLOW_THREADS/Py_END_ALLOW_THREADS lines.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue17899>
_______________________________________


More information about the Python-bugs-list mailing list