From: Berker Peksag Date: Tue, 13 Sep 2016 04:39:00 +0000 (+0300) Subject: Issue #27981: Fix refleak in fp_setreadl() X-Git-Tag: v3.6.0b2~232^2~1^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=720acbf31b960bd6fb5f6bf2ad6a3e319428749c;p=python Issue #27981: Fix refleak in fp_setreadl() Patch by David Dudson. --- diff --git a/Parser/tokenizer.c b/Parser/tokenizer.c index 184ffe7a7d..784b98caf9 100644 --- a/Parser/tokenizer.c +++ b/Parser/tokenizer.c @@ -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); } }