diff Python/ceval.c @ 29669:96ecaab4cba6 legacy-trunk

Fix SF #762455, segfault when sys.stdout is changed in getattr Will backport.
author Neal Norwitz <nnorwitz@gmail.com>
date Sun, 29 Jun 2003 14:48:32 +0000
parents fa97293533a9
children 4e254f028b76 3b59fa5d25b1
line wrap: on
line diff
--- a/Python/ceval.c	Sun Jun 29 05:46:54 2003 +0000
+++ b/Python/ceval.c	Sun Jun 29 14:48:32 2003 +0000
@@ -1501,6 +1501,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, 0))
 				err = PyFile_WriteString(" ", w);
 			if (err == 0)
@@ -1528,6 +1533,7 @@
 			    else
 			    	PyFile_SoftSpace(w, 1);
 			}
+			Py_XDECREF(w);
 			Py_DECREF(v);
 			Py_XDECREF(stream);
 			stream = NULL;