[Python-checkins] r70579 - python/branches/py3k/Modules/_fileio.c
kristjan.jonsson
python-checkins at python.org
Tue Mar 24 14:21:53 CET 2009
Author: kristjan.jonsson
Date: Tue Mar 24 14:21:53 2009
New Revision: 70579
Log:
http://bugs.python.org/issue5544
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.
Modified:
python/branches/py3k/Modules/_fileio.c
Modified: python/branches/py3k/Modules/_fileio.c
==============================================================================
--- python/branches/py3k/Modules/_fileio.c (original)
+++ python/branches/py3k/Modules/_fileio.c Tue Mar 24 14:21:53 2009
@@ -77,11 +77,15 @@
if (self->fd >= 0) {
int fd = self->fd;
self->fd = -1;
- Py_BEGIN_ALLOW_THREADS
- err = close(fd);
- if (err < 0)
- save_errno = errno;
- Py_END_ALLOW_THREADS
+ /* fd is accessible and someone else may have closed it */
+ if (_PyVerify_fd(fd)) {
+ Py_BEGIN_ALLOW_THREADS
+ err = close(fd);
+ if (err < 0)
+ save_errno = errno;
+ Py_END_ALLOW_THREADS
+ } else
+ save_errno = errno;
}
if (err < 0) {
errno = save_errno;
More information about the Python-checkins
mailing list