]> granicus.if.org Git - python/commitdiff
Issue #27981: Fix refleak in fp_setreadl()
authorBerker Peksag <berker.peksag@gmail.com>
Tue, 13 Sep 2016 04:39:00 +0000 (07:39 +0300)
committerBerker Peksag <berker.peksag@gmail.com>
Tue, 13 Sep 2016 04:39:00 +0000 (07:39 +0300)
Patch by David Dudson.

Parser/tokenizer.c

index 184ffe7a7d824c5c8a1943e4a2b8d30a989ac68f..784b98caf9fc61b66183c37cb6bc34dbaf6e5f26 100644 (file)
@@ -497,7 +497,7 @@ error:
 static int
 fp_setreadl(struct tok_state *tok, const char* enc)
 {
-    PyObject *readline = NULL, *stream = NULL, *io = NULL;
+    PyObject *readline = NULL, *stream = NULL, *io = NULL, *bufobj;
     _Py_IDENTIFIER(open);
     _Py_IDENTIFIER(readline);
     int fd;
@@ -528,9 +528,12 @@ fp_setreadl(struct tok_state *tok, const char* enc)
     readline = _PyObject_GetAttrId(stream, &PyId_readline);
     Py_XSETREF(tok->decoding_readline, readline);
     if (pos > 0) {
-        if (PyObject_CallObject(readline, NULL) == NULL) {
+        bufobj = PyObject_CallObject(readline, NULL);
+        if (bufobj == NULL) {
             readline = NULL;
             goto cleanup;
+        } else {
+            Py_DECREF(bufobj);
         }
     }