diff -r 4a0017722910 Modules/posixmodule.c --- a/Modules/posixmodule.c Sun Jun 09 21:10:13 2013 +0300 +++ b/Modules/posixmodule.c Sun Jun 09 19:20:27 2013 -0700 @@ -8,6 +8,7 @@ of the compiler used. Different compilers define their own feature test macro, e.g. '__BORLANDC__' or '_MSC_VER'. */ +#undef HAVE_FDOPENDIR #ifdef __APPLE__ /* * Step 1 of support for weak-linking a number of symbols existing on @@ -3421,7 +3422,9 @@ static PyObject * _posix_listdir(path_t *path, PyObject *list) { +#ifdef HAVE_FDOPENDIR int fd = -1; +#endif PyObject *v; DIR *dirp = NULL; @@ -3467,6 +3470,13 @@ } if (dirp == NULL) { +#ifdef HAVE_FDOPENDIR + if (fd != -1) { + Py_BEGIN_ALLOW_THREADS + close(fd); + Py_END_ALLOW_THREADS + } +#endif list = path_error(path); goto exit; } @@ -3510,8 +3520,10 @@ exit: if (dirp != NULL) { Py_BEGIN_ALLOW_THREADS +#ifdef HAVE_FDOPENDIR if (fd > -1) rewinddir(dirp); +#endif closedir(dirp); Py_END_ALLOW_THREADS }