diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2011-12-16 11:29:37 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2011-12-16 11:29:37 (GMT) |
commit | ab0e9f7089c04df546af6cacbc8751247cf4020a (patch) | |
tree | 3494351a976a17a62146a3ddd365fe2b5936fca4 /Modules/_io/fileio.c | |
parent | e2b2bf55b30299e310b246b5b4b6f5a5f66e75b2 (diff) | |
parent | c345ce1a69b3c4a46d87ef56d859bc70abfc74b4 (diff) | |
download | cpython-ab0e9f7089c04df546af6cacbc8751247cf4020a.zip cpython-ab0e9f7089c04df546af6cacbc8751247cf4020a.tar.gz cpython-ab0e9f7089c04df546af6cacbc8751247cf4020a.tar.bz2 |
Issue #10350: Read and save errno before calling a function which might overwrite it.
Original patch by Hallvard B Furuseth.
Diffstat (limited to 'Modules/_io/fileio.c')
-rw-r--r-- | Modules/_io/fileio.c | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/Modules/_io/fileio.c b/Modules/_io/fileio.c index 7364523..3829e0b 100644 --- a/Modules/_io/fileio.c +++ b/Modules/_io/fileio.c @@ -530,6 +530,7 @@ fileio_readinto(fileio *self, PyObject *args) { Py_buffer pbuf; Py_ssize_t n, len; + int err; if (self->fd < 0) return err_closed(); @@ -553,10 +554,12 @@ fileio_readinto(fileio *self, PyObject *args) Py_END_ALLOW_THREADS } else n = -1; + err = errno; PyBuffer_Release(&pbuf); if (n < 0) { - if (errno == EAGAIN) + if (err == EAGAIN) Py_RETURN_NONE; + errno = err; PyErr_SetFromErrno(PyExc_IOError); return NULL; } @@ -726,9 +729,11 @@ fileio_read(fileio *self, PyObject *args) n = -1; if (n < 0) { + int err = errno; Py_DECREF(bytes); - if (errno == EAGAIN) + if (err == EAGAIN) Py_RETURN_NONE; + errno = err; PyErr_SetFromErrno(PyExc_IOError); return NULL; } @@ -748,6 +753,7 @@ fileio_write(fileio *self, PyObject *args) { Py_buffer pbuf; Py_ssize_t n, len; + int err; if (self->fd < 0) return err_closed(); @@ -778,12 +784,14 @@ fileio_write(fileio *self, PyObject *args) Py_END_ALLOW_THREADS } else n = -1; + err = errno; PyBuffer_Release(&pbuf); if (n < 0) { - if (errno == EAGAIN) + if (err == EAGAIN) Py_RETURN_NONE; + errno = err; PyErr_SetFromErrno(PyExc_IOError); return NULL; } |