- (djm) Fix problem with debug mode and MaxStartups
diff --git a/ChangeLog b/ChangeLog
index 8481359..b36f9a4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -49,6 +49,7 @@
    - ho@cvs.openbsd.org      2000/07/10 10:30:25
      [cipher.c kex.c servconf.c]
      strtok() --> strsep(). (niels@ ok)
+ - (djm) Fix problem with debug mode and MaxStartups
 
 20000709
  - (djm) Only enable PAM_TTY kludge for Linux. Problem report from
diff --git a/session.c b/session.c
index 96a2d3b..abf3ef3 100644
--- a/session.c
+++ b/session.c
@@ -169,7 +169,8 @@
 	 * authentication.
 	 */
 	alarm(0);
-	close(startup_pipe);
+	if (startup_pipe != -1)
+		close(startup_pipe);
 
 	/*
 	 * Inform the channel mechanism that we are the server side and that
@@ -1792,7 +1793,8 @@
 	 * authentication.
 	 */
 	alarm(0);
-	close(startup_pipe);
+	if (startup_pipe != -1)
+		close(startup_pipe);
 	server_loop2();
 	if (xauthfile)
 		xauthfile_cleanup_proc(NULL);
diff --git a/sshd.c b/sshd.c
index fc8b17b..e53629d 100644
--- a/sshd.c
+++ b/sshd.c
@@ -855,6 +855,7 @@
 					sock_in = newsock;
 					sock_out = newsock;
 					pid = getpid();
+					startup_pipe = -1;
 					break;
 				} else {
 					/*