From 08fb98caac6896b233195d86a5b70ddf606b25fd Mon Sep 17 00:00:00 2001 From: Valtteri Koskivuori Date: Tue, 25 Jul 2023 21:04:23 +0300 Subject: [PATCH] Mail: Fix crash when closing window before IMAP::Client connects `MailWidget::m_imap_client` is only assigned after a connection is established, so the user might close the main window before that happens, especially if the connection hangs for whatever reason. Now we check the `OwnPtr` before working with it. --- Userland/Applications/Mail/MailWidget.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Userland/Applications/Mail/MailWidget.cpp b/Userland/Applications/Mail/MailWidget.cpp index c581994f42..b0fbfc1564 100644 --- a/Userland/Applications/Mail/MailWidget.cpp +++ b/Userland/Applications/Mail/MailWidget.cpp @@ -163,6 +163,10 @@ bool MailWidget::connect_and_login() void MailWidget::on_window_close() { + if (!m_imap_client) { + // User closed main window before a connection was established + return; + } auto response = move(MUST(m_imap_client->send_simple_command(IMAP::CommandType::Logout)->await()).release_value().get()); VERIFY(response.status() == IMAP::ResponseStatus::OK);