diff Python/ceval.c @ 29670:be99f5970688 2.2

Backport: Fix SF #762455, segfault when sys.stdout is changed in getattr Note: in 2.2, the problem was an infinite loop (at least for me).
author Neal Norwitz <nnorwitz@gmail.com>
date Sun, 29 Jun 2003 14:57:10 +0000
parents efa9a86464d3
children
line wrap: on
line diff
--- a/Python/ceval.c	Fri Jun 27 19:37:16 2003 +0000
+++ b/Python/ceval.c	Sun Jun 29 14:57:10 2003 +0000
@@ -1365,6 +1365,11 @@
 					err = -1;
 				}
 			}
+			/* PyFile_SoftSpace() can exececute arbitrary code
+			   if sys.stdout is an instance with a __getattr__.
+			   If __getattr__ raises an exception, w will
+			   be freed, so we need to prevent that temporarily. */
+			Py_XINCREF(w);
 			if (w != NULL && PyFile_SoftSpace(w, 1))
 				err = PyFile_WriteString(" ", w);
 			if (err == 0)
@@ -1390,6 +1395,7 @@
 			    }
 #endif
 			}
+			Py_XDECREF(w);
 			Py_DECREF(v);
 			Py_XDECREF(stream);
 			stream = NULL;