[Python-checkins] cpython (3.4): Issue #23571: If io.TextIOWrapper constructor fails in _Py_DisplaySourceLine(),

victor.stinner python-checkins at python.org
Wed Mar 25 02:47:31 CET 2015


https://hg.python.org/cpython/rev/004e3870d9e6
changeset:   95190:004e3870d9e6
branch:      3.4
parent:      95188:1c2376825dd2
user:        Victor Stinner <victor.stinner at gmail.com>
date:        Wed Mar 25 02:25:25 2015 +0100
summary:
  Issue #23571: If io.TextIOWrapper constructor fails in _Py_DisplaySourceLine(),
close the binary file to fix a resource warning.

files:
  Python/traceback.c |  9 ++++++++-
  1 files changed, 8 insertions(+), 1 deletions(-)


diff --git a/Python/traceback.c b/Python/traceback.c
--- a/Python/traceback.c
+++ b/Python/traceback.c
@@ -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++) {

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list