From: Serhiy Storchaka Date: Wed, 30 Mar 2016 17:41:15 +0000 (+0300) Subject: Issue #26494: Fixed crash on iterating exhausting iterators. X-Git-Tag: v3.6.0a1~294 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=ab479c49d31be03e85b824b8444b474b28e6db71;p=thirdparty%2FPython%2Fcpython.git 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. --- ab479c49d31be03e85b824b8444b474b28e6db71 diff --cc Misc/NEWS index 34ef0cd6b016,391bbf256e62..6fb0fc4fdda0 --- a/Misc/NEWS +++ b/Misc/NEWS @@@ -10,9 -10,11 +10,14 @@@ Release date: tb Core and Builtins ----------------- + - 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. + +- Issue #26574: Optimize ``bytes.replace(b'', b'.')`` and + ``bytearray.replace(b'', b'.')``. Patch written by Josh Snider. + - Issue #26581: If coding cookie is specified multiple times on a line in Python source code file, only the first one is taken to account. diff --cc Modules/posixmodule.c index 1cd0f24148c8,c95668b3fda6..9013888f290a --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@@ -11947,22 -11925,18 +11947,24 @@@ typedef struct #ifdef MS_WINDOWS +static int +ScandirIterator_is_closed(ScandirIterator *iterator) +{ + return iterator->handle == INVALID_HANDLE_VALUE; +} + static void -ScandirIterator_close(ScandirIterator *iterator) +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 * @@@ -12009,22 -11983,18 +12011,24 @@@ ScandirIterator_iternext(ScandirIterato #else /* POSIX */ +static int +ScandirIterator_is_closed(ScandirIterator *iterator) +{ + return !iterator->dirp; +} + static void -ScandirIterator_close(ScandirIterator *iterator) +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; }