From 72b7389e1b83b797b94f2b16f5bcc5a82c006e1f Mon Sep 17 00:00:00 2001 From: Richard Russon Date: Sat, 26 Oct 2019 14:27:46 +0100 Subject: [PATCH] NULL Mailbox pointer if it's deleted --- index.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/index.c b/index.c index 9bef52e07..ab1fc8f38 100644 --- a/index.c +++ b/index.c @@ -604,6 +604,26 @@ void update_index(struct Menu *menu, struct Context *ctx, int check, int oldcoun menu->current = ci_first_message(); } + +/** + * mailbox_index_observer - Listen for Mailbox changes - Implements ::observer_t() + */ +int mailbox_index_observer(struct NotifyCallback *nc) +{ + if (!nc) + return -1; + + if ((nc->event_type != NT_MAILBOX) || (nc->event_subtype != MBN_CLOSED)) + return 0; + + struct Mailbox **ptr = (struct Mailbox **) nc->data; + if (!ptr || !*ptr) + return 0; + + *ptr = NULL; + return 0; +} + /** * main_change_folder - Change to a different mailbox * @param menu Current Menu @@ -697,7 +717,11 @@ static int main_change_folder(struct Menu *menu, int op, struct Mailbox *m, * mutt_push/pop_current_menu() functions. If that changes, the menu * would need to be reset here, and the pager cleanup code after the * switch statement would need to be run. */ + if (m) + notify_observer_add(m->notify, NT_MAILBOX, 0, mailbox_index_observer, IP &m); mutt_folder_hook(buf, m ? m->name : NULL); + if (m) + notify_observer_remove(m->notify, mailbox_index_observer, IP &m); int flags = MUTT_OPEN_NO_FLAGS; if (C_ReadOnly || (op == OP_MAIN_CHANGE_FOLDER_READONLY)) -- 2.40.0