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

Skip to content

Commit e865128

Browse files
committed
properly decref the return value of close()
1 parent a33bce0 commit e865128

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

Modules/_io/_iomodule.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -465,11 +465,13 @@ io_open(PyObject *self, PyObject *args, PyObject *kwds)
465465

466466
error:
467467
if (result != NULL) {
468-
PyObject *exc, *val, *tb;
468+
PyObject *exc, *val, *tb, *close_result;
469469
PyErr_Fetch(&exc, &val, &tb);
470-
if (_PyObject_CallMethodId(result, &PyId_close, NULL) != NULL)
470+
close_result = _PyObject_CallMethodId(result, &PyId_close, NULL);
471+
if (close_result != NULL) {
472+
Py_DECREF(close_result);
471473
PyErr_Restore(exc, val, tb);
472-
else {
474+
} else {
473475
PyObject *exc2, *val2, *tb2;
474476
PyErr_Fetch(&exc2, &val2, &tb2);
475477
PyErr_NormalizeException(&exc, &val, &tb);

0 commit comments

Comments
 (0)