Fix crash when logging out from ICS
authorH.G.Muller <hgm@hgm-xboard.(none)>
Thu, 28 Jul 2016 17:49:02 +0000 (19:49 +0200)
committerH.G.Muller <hgm@hgm-xboard.(none)>
Thu, 28 Jul 2016 17:49:02 +0000 (19:49 +0200)
The patch that sent "logout" to the ICS on a fatal error backfired when
the 'fatal error' was a disconnect, and caused a crash on Mac. We now
suppress sending of this "logout" command in the disconnect case,
communicated in a kludgy way (by requesting exit status 6666).

backend.c
dialogs.c

index b288d6b..776f751 100644 (file)
--- a/backend.c
+++ b/backend.c
@@ -4301,7 +4301,7 @@ read_from_ics (InputSourceRef isr, VOIDSTAR closure, char *data, int count, int
 
     } else if (count == 0) {
        RemoveInputSource(isr);
-        DisplayFatalError(_("Connection closed by ICS"), 0, 0);
+        DisplayFatalError(_("Connection closed by ICS"), 0, 6666);
     } else {
        DisplayFatalError(_("Error reading from ICS"), error, 1);
     }
index d0c372a..af11b49 100644 (file)
--- a/dialogs.c
+++ b/dialogs.c
@@ -2523,12 +2523,12 @@ DisplayMoveError (String message)
 void
 DisplayFatalError (String message, int error, int status)
 {
-    char buf[MSG_SIZ];
+    char buf[MSG_SIZ], logout = appData.icsActive;
 
     if(status == 666) { // ignore this error when ICS Console window is up
        if(shellUp[ChatDlg]) return;
        status = 0;
-    }
+    } else if(status == 6666) status = logout = 0; // 6666 = kludge that indicates ICS connection already closed
 
     errorExitStatus = status;
     if (error == 0) {
@@ -2541,7 +2541,7 @@ DisplayFatalError (String message, int error, int status)
     }
     if(mainOptions[W_BOARD].handle) {
        if (appData.popupExitMessage) {
-           if(appData.icsActive) SendToICS("logout\n"); // [HGM] make sure no new games will be started
+           if(logout) SendToICS("logout\n"); // [HGM] make sure no new games will be started
            ErrorPopUp(status ? _("Fatal Error") : _("Exiting"), message, TRUE);
        } else {
            ExitEvent(status);