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.
This commit is contained in:
Serhiy Storchaka 2016-03-30 20:41:15 +03:00
commit ab479c49d3
19 changed files with 94 additions and 24 deletions

View file

@ -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;
Py_BEGIN_ALLOW_THREADS
FindClose(iterator->handle);
Py_END_ALLOW_THREADS
iterator->handle = INVALID_HANDLE_VALUE;
Py_BEGIN_ALLOW_THREADS
FindClose(handle);
Py_END_ALLOW_THREADS
}
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;
Py_BEGIN_ALLOW_THREADS
closedir(iterator->dirp);
Py_END_ALLOW_THREADS
iterator->dirp = NULL;
Py_BEGIN_ALLOW_THREADS
closedir(dirp);
Py_END_ALLOW_THREADS
return;
}