]> granicus.if.org Git - neomutt/commitdiff
Do not link in a new Account after a failed login
authorPietro Cerutti <gahr@gahr.ch>
Thu, 2 May 2019 09:09:08 +0000 (09:09 +0000)
committerRichard Russon <rich@flatcap.org>
Thu, 2 May 2019 12:52:32 +0000 (13:52 +0100)
Fixes #1690

init.c
mx.c

diff --git a/init.c b/init.c
index ce748347f22e2fdc370c755292e4816975a765fc..c44cd21f017fec9e512cc3fdb2a6cac1b1f79009 100644 (file)
--- a/init.c
+++ b/init.c
@@ -1344,7 +1344,6 @@ static enum CommandResult parse_mailboxes(struct Buffer *buf, struct Buffer *s,
     {
       a = account_new();
       a->magic = m->magic;
-      TAILQ_INSERT_TAIL(&AllAccounts, a, entries);
       new_account = true;
     }
 
@@ -1370,8 +1369,16 @@ static enum CommandResult parse_mailboxes(struct Buffer *buf, struct Buffer *s,
     {
       //error
       mailbox_free(&m);
+      if (new_account)
+      {
+        FREE(&a);
+      }
       continue;
     }
+    if (new_account)
+    {
+      TAILQ_INSERT_TAIL(&AllAccounts, a, entries);
+    }
 
     struct MailboxNode *mn = mutt_mem_calloc(1, sizeof(*mn));
     mn->mailbox = m;
diff --git a/mx.c b/mx.c
index 99df66c67d49379e279457c02559727a15e650bb..aa39dadcb9f90c35f6c3005ddd863817475fe88d 100644 (file)
--- a/mx.c
+++ b/mx.c
@@ -261,17 +261,26 @@ struct Context *mx_mbox_open(struct Mailbox *m, OpenMailboxFlags flags)
   if (!m->account)
   {
     struct Account *a = mx_ac_find(m);
+    bool new_account = false;
     if (!a)
     {
       a = account_new();
       a->magic = m->magic;
-      TAILQ_INSERT_TAIL(&AllAccounts, a, entries);
+      new_account = true;
     }
     if (mx_ac_add(a, m) < 0)
     {
       ctx_free(&ctx);
+      if (new_account)
+      {
+        FREE(&a);
+      }
       return NULL;
     }
+    if (new_account)
+    {
+      TAILQ_INSERT_TAIL(&AllAccounts, a, entries);
+    }
   }
 
   ctx->msgnotreadyet = -1;