Make sure we do notify_remote_exit(ssh->frontend) _before_
[u/mdw/putty] / ssh.c
diff --git a/ssh.c b/ssh.c
index 72f142f..7f3748a 100644 (file)
--- a/ssh.c
+++ b/ssh.c
@@ -2383,7 +2383,8 @@ static void ssh_process_queued_incoming_data(Ssh ssh)
 
 static void ssh_set_frozen(Ssh ssh, int frozen)
 {
-    sk_set_frozen(ssh->s, frozen);
+    if (ssh->s)
+       sk_set_frozen(ssh->s, frozen);
     ssh->frozen = frozen;
 }
 
@@ -2516,6 +2517,9 @@ static int ssh_closing(Plug plug, const char *error_msg, int error_code,
         error_msg = "Server unexpectedly closed network connection";
     }
 
+    if (need_notify)
+        notify_remote_exit(ssh->frontend);
+
     if (error_msg) {
        /* A socket error has occurred. */
        logevent(error_msg);
@@ -2523,8 +2527,6 @@ static int ssh_closing(Plug plug, const char *error_msg, int error_code,
     } else {
         logevent("Server closed network connection");
     }
-    if (need_notify)
-        notify_remote_exit(ssh->frontend);
     return 0;
 }
 
@@ -2932,6 +2934,7 @@ static int do_ssh1_login(Ssh ssh, unsigned char *in, int inlen,
         if (s->dlgret == 0) {
             ssh->close_expected = TRUE;
             ssh_closing((Plug)ssh, NULL, 0, 0);
+           crStop(0);
         }
     }
 
@@ -3012,6 +3015,7 @@ static int do_ssh1_login(Ssh ssh, unsigned char *in, int inlen,
            if (s->dlgret == 0) {
                ssh->close_expected = TRUE;
                ssh_closing((Plug)ssh, NULL, 0, 0);
+               crStop(0);
            }
         }
     }
@@ -3908,7 +3912,7 @@ static void ssh_setup_portfwd(Ssh ssh, const Config *cfg)
                    strcpy(saddr, sports);
                n = 0;
            }
-           if (n < 255) sports[n++] = *portfwd_strptr++;
+           if (n < lenof(sports)-1) sports[n++] = *portfwd_strptr++;
        }
        sports[n] = 0;
        if (type != 'D') {
@@ -3916,14 +3920,14 @@ static void ssh_setup_portfwd(Ssh ssh, const Config *cfg)
                portfwd_strptr++;
            n = 0;
            while (*portfwd_strptr && *portfwd_strptr != ':') {
-               if (n < 255) host[n++] = *portfwd_strptr++;
+               if (n < lenof(host)-1) host[n++] = *portfwd_strptr++;
            }
            host[n] = 0;
            if (*portfwd_strptr == ':')
                portfwd_strptr++;
            n = 0;
            while (*portfwd_strptr) {
-               if (n < 255) dports[n++] = *portfwd_strptr++;
+               if (n < lenof(dports)-1) dports[n++] = *portfwd_strptr++;
            }
            dports[n] = 0;
            portfwd_strptr++;
@@ -5219,6 +5223,7 @@ static int do_ssh2_transport(Ssh ssh, void *vin, int inlen,
            if (s->dlgret == 0) {
                ssh->close_expected = TRUE;
                ssh_closing((Plug)ssh, NULL, 0, 0);
+               crStop(0);
            }
        }
 
@@ -5243,6 +5248,7 @@ static int do_ssh2_transport(Ssh ssh, void *vin, int inlen,
            if (s->dlgret == 0) {
                ssh->close_expected = TRUE;
                ssh_closing((Plug)ssh, NULL, 0, 0);
+               crStop(0);
            }
        }
 
@@ -5267,6 +5273,7 @@ static int do_ssh2_transport(Ssh ssh, void *vin, int inlen,
            if (s->dlgret == 0) {
                ssh->close_expected = TRUE;
                ssh_closing((Plug)ssh, NULL, 0, 0);
+               crStop(0);
            }
        }