diff options
| author | Serhiy Storchaka <storchaka@gmail.com> | 2016-03-30 20:41:15 +0300 |
|---|---|---|
| committer | Serhiy Storchaka <storchaka@gmail.com> | 2016-03-30 20:41:15 +0300 |
| commit | ab479c49d31be03e85b824b8444b474b28e6db71 (patch) | |
| tree | f171c7cb1f6e5568b7309665b0e87dae9dda67f5 /Modules | |
| parent | fe4c01268cf9e94869a476495213fc362ef3a697 (diff) | |
| parent | fbb1c5ee068d209e33f6e15ecb4821d5d8b107fa (diff) | |
| download | cpython-git-ab479c49d31be03e85b824b8444b474b28e6db71.tar.gz | |
Issue #26494: Fixed crash on iterating exhausting iterators.
Affected classes are generic sequence iterators, iterators of str, bytes,
bytearray, list, tuple, set, frozenset, dict, OrderedDict, corresponding
views and os.scandir() iterator.
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 1cd0f24148..9013888f29 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -11956,13 +11956,15 @@ ScandirIterator_is_closed(ScandirIterator *iterator) static void ScandirIterator_closedir(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 * @@ -12018,13 +12020,15 @@ ScandirIterator_is_closed(ScandirIterator *iterator) static void ScandirIterator_closedir(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; } |
