#3242: fix a crash in "print", if sys.stdout is set to a custom object,
whose write() method installs another sys.stdout.

Backport of r64633
diff --git a/Python/ceval.c b/Python/ceval.c
index 06d524b..9bc147b 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -1603,9 +1603,11 @@
 							"lost sys.stdout");
 			}
 			if (w != NULL) {
+				Py_INCREF(w);
 				err = PyFile_WriteString("\n", w);
 				if (err == 0)
 					PyFile_SoftSpace(w, 0);
+				Py_DECREF(w);
 			}
 			Py_XDECREF(stream);
 			stream = NULL;