Skip to content

Commit ba30883

Browse files
committed
Issue #18520: Fix initstdio(), handle PySys_SetObject() failure
1 parent 5b3b100 commit ba30883

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

Python/pythonrun.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1159,8 +1159,14 @@ initstdio(void)
11591159
}
11601160
PyErr_Clear(); /* Not a fatal error if codec isn't available */
11611161

1162-
PySys_SetObject("__stderr__", std);
1163-
PySys_SetObject("stderr", std);
1162+
if (PySys_SetObject("__stderr__", std) < 0) {
1163+
Py_DECREF(std);
1164+
goto error;
1165+
}
1166+
if (PySys_SetObject("stderr", std) < 0) {
1167+
Py_DECREF(std);
1168+
goto error;
1169+
}
11641170
Py_DECREF(std);
11651171
#endif
11661172

0 commit comments

Comments
 (0)