From aa5bbfaa77a14634a035233a8879351d320bad6c Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Fri, 8 Nov 2013 00:29:41 +0100 Subject: [PATCH] Issue #19437: Fix _io._IOBase.close(), handle _PyObject_SetAttrId() failure --- Modules/_io/iobase.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Modules/_io/iobase.c b/Modules/_io/iobase.c index b58687e3301..3da7e5d89c3 100644 --- a/Modules/_io/iobase.c +++ b/Modules/_io/iobase.c @@ -186,11 +186,16 @@ iobase_close(PyObject *self, PyObject *args) Py_RETURN_NONE; res = PyObject_CallMethodObjArgs(self, _PyIO_str_flush, NULL); - _PyObject_SetAttrId(self, &PyId___IOBase_closed, Py_True); - if (res == NULL) { + + if (_PyObject_SetAttrId(self, &PyId___IOBase_closed, Py_True) < 0) { + Py_XDECREF(res); return NULL; } - Py_XDECREF(res); + + if (res == NULL) + return NULL; + + Py_DECREF(res); Py_RETURN_NONE; }