diff options
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/posixmodule.c | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 710bcde..c95668b 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -11928,13 +11928,15 @@ typedef struct { static void ScandirIterator_close(ScandirIterator *iterator) { - if (iterator->handle == INVALID_HANDLE_VALUE) + HANDLE handle = iterator->handle; + + if (handle == INVALID_HANDLE_VALUE) return; + iterator->handle = INVALID_HANDLE_VALUE; Py_BEGIN_ALLOW_THREADS - FindClose(iterator->handle); + FindClose(handle); Py_END_ALLOW_THREADS - iterator->handle = INVALID_HANDLE_VALUE; } static PyObject * @@ -11984,13 +11986,15 @@ ScandirIterator_iternext(ScandirIterator *iterator) static void ScandirIterator_close(ScandirIterator *iterator) { - if (!iterator->dirp) + DIR *dirp = iterator->dirp; + + if (!dirp) return; + iterator->dirp = NULL; Py_BEGIN_ALLOW_THREADS - closedir(iterator->dirp); + closedir(dirp); Py_END_ALLOW_THREADS - iterator->dirp = NULL; return; } |