Core and Builtins
-----------------
+- Issue #17899: Fix rare file descriptor leak in os.listdir().
+
- Issue #10241: Clear extension module dict copies at interpreter shutdown.
Patch by Neil Schemenauer, minimally modified.
static PyObject *
_posix_listdir(path_t *path, PyObject *list)
{
- int fd = -1;
-
PyObject *v;
DIR *dirp = NULL;
struct dirent *ep;
int return_str; /* if false, return bytes */
+#ifdef HAVE_FDOPENDIR
+ int fd = -1;
+#endif
errno = 0;
#ifdef HAVE_FDOPENDIR
if (dirp == NULL) {
list = path_error(path);
+#ifdef HAVE_FDOPENDIR
+ if (fd != -1) {
+ Py_BEGIN_ALLOW_THREADS
+ close(fd);
+ Py_END_ALLOW_THREADS
+ }
+#endif
goto exit;
}
if ((list = PyList_New(0)) == NULL) {
exit:
if (dirp != NULL) {
Py_BEGIN_ALLOW_THREADS
+#ifdef HAVE_FDOPENDIR
if (fd > -1)
rewinddir(dirp);
+#endif
closedir(dirp);
Py_END_ALLOW_THREADS
}