summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2015-03-25 01:25:25 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2015-03-25 01:25:25 (GMT)
commit81f241ab2e19db9e421a300c00f9fb1c4e0003df (patch)
tree826aecc4575aaaca63a6d02900850382b36dbaa3 /Python
parent84092ac3705ffe371f5f1ec8ecc8c2830861ba9e (diff)
downloadcpython-81f241ab2e19db9e421a300c00f9fb1c4e0003df.zip
cpython-81f241ab2e19db9e421a300c00f9fb1c4e0003df.tar.gz
cpython-81f241ab2e19db9e421a300c00f9fb1c4e0003df.tar.bz2
Issue #23571: If io.TextIOWrapper constructor fails in _Py_DisplaySourceLine(),
close the binary file to fix a resource warning.
Diffstat (limited to 'Python')
-rw-r--r--Python/traceback.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/Python/traceback.c b/Python/traceback.c
index c2aba52..2bea29e 100644
--- a/Python/traceback.c
+++ b/Python/traceback.c
@@ -309,13 +309,20 @@ _Py_DisplaySourceLine(PyObject *f, PyObject *filename, int lineno, int indent)
}
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++) {