changeset: 95190:004e3870d9e6 branch: 3.4 parent: 95188:1c2376825dd2 user: Victor Stinner date: Wed Mar 25 02:25:25 2015 +0100 files: Python/traceback.c description: Issue #23571: If io.TextIOWrapper constructor fails in _Py_DisplaySourceLine(), close the binary file to fix a resource warning. diff -r 1c2376825dd2 -r 004e3870d9e6 Python/traceback.c --- a/Python/traceback.c Wed Mar 25 01:54:46 2015 +0100 +++ b/Python/traceback.c Wed Mar 25 02:25:25 2015 +0100 @@ -309,13 +309,20 @@ } fob = _PyObject_CallMethodId(io, &PyId_TextIOWrapper, "Os", binary, encoding); Py_DECREF(io); - Py_DECREF(binary); PyMem_FREE(found_encoding); if (fob == NULL) { PyErr_Clear(); + + res = _PyObject_CallMethodId(binary, &PyId_close, ""); + Py_DECREF(binary); + if (res) + Py_DECREF(res); + else + PyErr_Clear(); return 0; } + Py_DECREF(binary); /* get the line number lineno */ for (i = 0; i < lineno; i++) {