summaryrefslogtreecommitdiffstats
path: root/Modules/posixmodule.c
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2016-03-30 17:40:02 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2016-03-30 17:40:02 (GMT)
commitfbb1c5ee068d209e33f6e15ecb4821d5d8b107fa (patch)
tree4ae6657a598c5cfe5357f3106d956ed721d83e24 /Modules/posixmodule.c
parent13b3acd13e35b5e619c3d1aab90aaf54abc1fb53 (diff)
downloadcpython-fbb1c5ee068d209e33f6e15ecb4821d5d8b107fa.zip
cpython-fbb1c5ee068d209e33f6e15ecb4821d5d8b107fa.tar.gz
cpython-fbb1c5ee068d209e33f6e15ecb4821d5d8b107fa.tar.bz2
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/posixmodule.c')
-rw-r--r--Modules/posixmodule.c16
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;
}