diff options
author | 2018-07-17 00:09:32 -0700 | |
---|---|---|
committer | 2018-07-17 00:09:32 -0700 | |
commit | 6020d98beaf6b9945beb7560f9a1df361e0ba4dd (patch) | |
tree | e9be672ac74bbee3c0cf97725a71f7a115b054b2 /Modules/_io | |
parent | bpo-33967: Fix wrong use of assertRaises (GH-8306) (diff) | |
download | cpython-6020d98beaf6b9945beb7560f9a1df361e0ba4dd.tar.gz cpython-6020d98beaf6b9945beb7560f9a1df361e0ba4dd.tar.bz2 cpython-6020d98beaf6b9945beb7560f9a1df361e0ba4dd.zip |
bpo-34068: _io__IOBase_close_impl could call _PyObject_SetAttrId with an exception set (GH-8282)
(cherry picked from commit 28f07364f066792ceee93231dbb80ae8ad98b2bb)
Co-authored-by: Zackery Spytz <zspytz@gmail.com>
Diffstat (limited to 'Modules/_io')
-rw-r--r-- | Modules/_io/iobase.c | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/Modules/_io/iobase.c b/Modules/_io/iobase.c index 0c329bff840..5b71732ef19 100644 --- a/Modules/_io/iobase.c +++ b/Modules/_io/iobase.c @@ -224,8 +224,8 @@ static PyObject * _io__IOBase_close_impl(PyObject *self) /*[clinic end generated code: output=63c6a6f57d783d6d input=f4494d5c31dbc6b7]*/ { - PyObject *res; - int closed = iobase_is_closed(self); + PyObject *res, *exc, *val, *tb; + int rc, closed = iobase_is_closed(self); if (closed < 0) { return NULL; @@ -236,9 +236,11 @@ _io__IOBase_close_impl(PyObject *self) res = PyObject_CallMethodObjArgs(self, _PyIO_str_flush, NULL); - if (_PyObject_SetAttrId(self, &PyId___IOBase_closed, Py_True) < 0) { - Py_XDECREF(res); - return NULL; + PyErr_Fetch(&exc, &val, &tb); + rc = _PyObject_SetAttrId(self, &PyId___IOBase_closed, Py_True); + _PyErr_ChainExceptions(exc, val, tb); + if (rc < 0) { + Py_CLEAR(res); } if (res == NULL) |