[Python-checkins] cpython (2.7): properly decref the return value of close()

benjamin.peterson python-checkins at python.org
Sat Jul 5 02:18:04 CEST 2014


http://hg.python.org/cpython/rev/5563f895b215
changeset:   91545:5563f895b215
branch:      2.7
parent:      91536:f2e6c33ce3e9
user:        Benjamin Peterson <benjamin at python.org>
date:        Fri Jul 04 17:00:25 2014 -0700
summary:
  properly decref the return value of close()

files:
  Modules/_io/_iomodule.c |  8 +++++---
  1 files changed, 5 insertions(+), 3 deletions(-)


diff --git a/Modules/_io/_iomodule.c b/Modules/_io/_iomodule.c
--- a/Modules/_io/_iomodule.c
+++ b/Modules/_io/_iomodule.c
@@ -526,11 +526,13 @@
 
   error:
     if (result != NULL) {
-        PyObject *exc, *val, *tb;
+        PyObject *exc, *val, *tb, *close_result;
         PyErr_Fetch(&exc, &val, &tb);
-        if (PyObject_CallMethod(result, "close", NULL) != NULL)
+        close_result = PyObject_CallMethod(result, "close", NULL);
+        if (close_result != NULL) {
+            Py_DECREF(close_result);
             PyErr_Restore(exc, val, tb);
-        else {
+        } else {
             Py_XDECREF(exc);
             Py_XDECREF(val);
             Py_XDECREF(tb);

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


More information about the Python-checkins mailing list