(original) (raw)

changeset: 103730:aa88456f1749 branch: 3.5 parent: 103725:138625694ed6 user: Berker Peksag berker.peksag@gmail.com date: Tue Sep 13 07:39:00 2016 +0300 files: Parser/tokenizer.c description: Issue #27981: Fix refleak in fp_setreadl() Patch by David Dudson. diff -r 138625694ed6 -r aa88456f1749 Parser/tokenizer.c --- a/Parser/tokenizer.c Tue Sep 13 04:49:12 2016 +0300 +++ b/Parser/tokenizer.c Tue Sep 13 07:39:00 2016 +0300 @@ -497,7 +497,7 @@ 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 @@ 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); } } /berker.peksag@gmail.com