From ba30883f60271be3b4b8c14735566c943a83c68f Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Mon, 22 Jul 2013 23:55:19 +0200 Subject: [PATCH] Issue #18520: Fix initstdio(), handle PySys_SetObject() failure --- Python/pythonrun.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Python/pythonrun.c b/Python/pythonrun.c index 30e5e6f0c37..18c2baa656d 100644 --- a/Python/pythonrun.c +++ b/Python/pythonrun.c @@ -1159,8 +1159,14 @@ initstdio(void) } PyErr_Clear(); /* Not a fatal error if codec isn't available */ - PySys_SetObject("__stderr__", std); - PySys_SetObject("stderr", std); + if (PySys_SetObject("__stderr__", std) < 0) { + Py_DECREF(std); + goto error; + } + if (PySys_SetObject("stderr", std) < 0) { + Py_DECREF(std); + goto error; + } Py_DECREF(std); #endif