Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit aa5bbfa

Browse files
committed
Issue #19437: Fix _io._IOBase.close(), handle _PyObject_SetAttrId() failure
1 parent 50abf22 commit aa5bbfa

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

Modules/_io/iobase.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,11 +186,16 @@ iobase_close(PyObject *self, PyObject *args)
186186
Py_RETURN_NONE;
187187

188188
res = PyObject_CallMethodObjArgs(self, _PyIO_str_flush, NULL);
189-
_PyObject_SetAttrId(self, &PyId___IOBase_closed, Py_True);
190-
if (res == NULL) {
189+
190+
if (_PyObject_SetAttrId(self, &PyId___IOBase_closed, Py_True) < 0) {
191+
Py_XDECREF(res);
191192
return NULL;
192193
}
193-
Py_XDECREF(res);
194+
195+
if (res == NULL)
196+
return NULL;
197+
198+
Py_DECREF(res);
194199
Py_RETURN_NONE;
195200
}
196201

0 commit comments

Comments
 (0)