mirror of
https://github.com/python/cpython.git
synced 2025-09-28 11:15:17 +00:00
Someone may have closed the file descriptor, with something like f = open('test.test', 'w') os.close(f.fileno()) f.close() Protect against this by checking fd on windows before closing.
This commit is contained in:
parent
7c43524d3c
commit
dc7c128d74
1 changed files with 9 additions and 5 deletions
|
@ -77,11 +77,15 @@ internal_close(PyFileIOObject *self)
|
||||||
if (self->fd >= 0) {
|
if (self->fd >= 0) {
|
||||||
int fd = self->fd;
|
int fd = self->fd;
|
||||||
self->fd = -1;
|
self->fd = -1;
|
||||||
Py_BEGIN_ALLOW_THREADS
|
/* fd is accessible and someone else may have closed it */
|
||||||
err = close(fd);
|
if (_PyVerify_fd(fd)) {
|
||||||
if (err < 0)
|
Py_BEGIN_ALLOW_THREADS
|
||||||
save_errno = errno;
|
err = close(fd);
|
||||||
Py_END_ALLOW_THREADS
|
if (err < 0)
|
||||||
|
save_errno = errno;
|
||||||
|
Py_END_ALLOW_THREADS
|
||||||
|
} else
|
||||||
|
save_errno = errno;
|
||||||
}
|
}
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
errno = save_errno;
|
errno = save_errno;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue