]> granicus.if.org Git - neomutt/commitdiff
Do not use disconnected socket.
authorTobias Stoeckmann <tobias@stoeckmann.org>
Fri, 26 Oct 2018 17:37:31 +0000 (19:37 +0200)
committerRichard Russon <rich@flatcap.org>
Sat, 27 Oct 2018 11:03:51 +0000 (12:03 +0100)
If an IMAP connection was never set up, do not try to write a LOGOUT
command through that connection or to close that socket.

Both results in segmentation faults.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
imap/imap.c

index f85336b3469137773f5d9b3bf83382f86438e624..62e5a7478671ca518b9bd05b149b6c639a9070c4 100644 (file)
@@ -1192,15 +1192,18 @@ void imap_logout(struct ImapAccountData **adata)
 {
   /* we set status here to let imap_handle_untagged know we _expect_ to
    * receive a bye response (so it doesn't freak out and close the conn) */
-  (*adata)->status = IMAP_BYE;
-  imap_cmd_start(*adata, "LOGOUT");
-  if (ImapPollTimeout <= 0 || mutt_socket_poll((*adata)->conn, ImapPollTimeout) != 0)
+  if ((*adata)->state != IMAP_DISCONNECTED)
   {
-    while (imap_cmd_step(*adata) == IMAP_CMD_CONTINUE)
-      ;
+    (*adata)->status = IMAP_BYE;
+    imap_cmd_start(*adata, "LOGOUT");
+    if (ImapPollTimeout <= 0 || mutt_socket_poll((*adata)->conn, ImapPollTimeout) != 0)
+    {
+      while (imap_cmd_step(*adata) == IMAP_CMD_CONTINUE)
+        ;
+    }
+    mutt_socket_close((*adata)->conn);
   }
 
-  mutt_socket_close((*adata)->conn);
   imap_adata_free((void **) adata);
 }