mirror of
https://github.com/python/cpython.git
synced 2025-09-24 09:23:02 +00:00
Issue #23571: If io.TextIOWrapper constructor fails in _Py_DisplaySourceLine(),
close the binary file to fix a resource warning.
This commit is contained in:
parent
84092ac370
commit
81f241ab2e
1 changed files with 8 additions and 1 deletions
|
@ -309,13 +309,20 @@ _Py_DisplaySourceLine(PyObject *f, PyObject *filename, int lineno, int indent)
|
||||||
}
|
}
|
||||||
fob = _PyObject_CallMethodId(io, &PyId_TextIOWrapper, "Os", binary, encoding);
|
fob = _PyObject_CallMethodId(io, &PyId_TextIOWrapper, "Os", binary, encoding);
|
||||||
Py_DECREF(io);
|
Py_DECREF(io);
|
||||||
Py_DECREF(binary);
|
|
||||||
PyMem_FREE(found_encoding);
|
PyMem_FREE(found_encoding);
|
||||||
|
|
||||||
if (fob == NULL) {
|
if (fob == NULL) {
|
||||||
PyErr_Clear();
|
PyErr_Clear();
|
||||||
|
|
||||||
|
res = _PyObject_CallMethodId(binary, &PyId_close, "");
|
||||||
|
Py_DECREF(binary);
|
||||||
|
if (res)
|
||||||
|
Py_DECREF(res);
|
||||||
|
else
|
||||||
|
PyErr_Clear();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Py_DECREF(binary);
|
||||||
|
|
||||||
/* get the line number lineno */
|
/* get the line number lineno */
|
||||||
for (i = 0; i < lineno; i++) {
|
for (i = 0; i < lineno; i++) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue