]> granicus.if.org Git - python/commitdiff
properly decref the return value of close()
authorBenjamin Peterson <benjamin@python.org>
Sat, 5 Jul 2014 00:00:25 +0000 (17:00 -0700)
committerBenjamin Peterson <benjamin@python.org>
Sat, 5 Jul 2014 00:00:25 +0000 (17:00 -0700)
Modules/_io/_iomodule.c

index 40acdf5589071f821c3023ffc2fd402419c0b09a..29db1642c43a8a954c1dcc0ffcd007d8fabbb4c8 100644 (file)
@@ -526,11 +526,13 @@ io_open(PyObject *self, PyObject *args, PyObject *kwds)
 
   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);