Commits

John Mulligan committed 87e7f6c

fslib: make fdlistdir/fditerdir dup the fd it is given

This is a minor backwards incompatible change. Use of the previous
version of the API had demonstrated that the previous approach was
error prone because any time you wanted to do something practical
with the dir fd you'd have to remember to dup it. There could have
also been potential issues with race conditions in multithreaded
code.

Comments (0)

Files changed (1)

     reslist = PyList_New(0);
     if (reslist == NULL) return NULL;
 
-    dirh = fdopendir(dirfd);
+    dirh = fdopendir(dup(dirfd));
     if (dirh == NULL) {
         Py_XDECREF(reslist);
         PyErr_SetFromErrno(PyExc_OSError);
     }
 
     Py_BEGIN_ALLOW_THREADS
-    temp = fdopendir(dirfd);
+    temp = fdopendir(dup(dirfd));
     Py_END_ALLOW_THREADS
     if (temp == NULL) {
         PyErr_SetFromErrno(PyExc_OSError);