From 720acbf31b960bd6fb5f6bf2ad6a3e319428749c Mon Sep 17 00:00:00 2001 From: Berker Peksag Date: Tue, 13 Sep 2016 07:39:00 +0300 Subject: [PATCH 1/2] Issue #27981: Fix refleak in fp_setreadl() Patch by David Dudson. --- Parser/tokenizer.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Parser/tokenizer.c b/Parser/tokenizer.c index 184ffe7a7d8..784b98caf9f 100644 --- a/Parser/tokenizer.c +++ b/Parser/tokenizer.c @@ -497,7 +497,7 @@ fp_readl(char *s, int size, struct tok_state *tok) 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); } } From ac2d1c71534f3de62980b0e953eaf6f31d8fd517 Mon Sep 17 00:00:00 2001 From: Berker Peksag Date: Tue, 13 Sep 2016 07:55:54 +0300 Subject: [PATCH 2/2] Issue #27952: Capture stderr in run_script() --- Lib/test/test_tools/test_fixcid.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Lib/test/test_tools/test_fixcid.py b/Lib/test/test_tools/test_fixcid.py index 7f25c173982..bce029b1aac 100644 --- a/Lib/test/test_tools/test_fixcid.py +++ b/Lib/test/test_tools/test_fixcid.py @@ -83,7 +83,8 @@ def run_script(self, input="", *, args=("-",), substfile="xx yy\n"): script = os.path.join(scriptsdir, "fixcid.py") with support.swap_attr(sys, "argv", argv), \ support.swap_attr(sys, "stdin", StringIO(input)), \ - support.captured_stdout() as output: + support.captured_stdout() as output, \ + support.captured_stderr(): try: runpy.run_path(script, run_name="__main__") except SystemExit as exit: