keep exitfunc alive while calling it
diff --git a/Python/pythonrun.c b/Python/pythonrun.c
index 0666c5a..9e402a6 100644
--- a/Python/pythonrun.c
+++ b/Python/pythonrun.c
@@ -605,12 +605,14 @@
 
 	if (exitfunc) {
 		object *res;
+		INCREF(exitfunc);
 		sysset("exitfunc", (object *)NULL);
 		res = call_object(exitfunc, (object *)NULL);
 		if (res == NULL) {
 			fprintf(stderr, "Error in sys.exitfunc:\n");
 			print_error();
 		}
+		DECREF(exitfunc);
 	}
 
 	flushline();