From 54e924977b283c507b6864818d062fc26c69c5de Mon Sep 17 00:00:00 2001 From: Pietro Cerutti Date: Thu, 2 May 2019 09:09:08 +0000 Subject: [PATCH] Do not link in a new Account after a failed login Fixes #1690 --- init.c | 9 ++++++++- mx.c | 11 ++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/init.c b/init.c index ce748347f..c44cd21f0 100644 --- 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 99df66c67..aa39dadcb 100644 --- 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; -- 2.40.0