From e29fceaee47e0a2edba83605c7fa2789cfb8de1e Mon Sep 17 00:00:00 2001 From: Konstantinos Sideris Date: Fri, 31 Aug 2018 09:10:47 +0300 Subject: Fix a use-after-free error during logout --- src/MainWindow.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'src/MainWindow.cpp') diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index a93f0c9f..95c56554 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -441,15 +441,22 @@ MainWindow::showSolidOverlayModal(QWidget *content, QFlags fl } void -MainWindow::openLogoutDialog(std::function callback) +MainWindow::openLogoutDialog() { auto dialog = new dialogs::Logout(this); - connect(dialog, &dialogs::Logout::closing, this, [this, callback](bool logging_out) { + connect(dialog, &dialogs::Logout::closing, this, [this](bool logging_out) { if (modal_) modal_->hide(); - if (logging_out) - callback(); + // By initiating the logout process a new overlay widget + // will replace & destroy the previous widget (logout dialog). + // + // This will force the destruction of the logout widget to + // happen after the click event has been fully processed. + QTimer::singleShot(0, this, [logging_out, this]() { + if (logging_out) + chat_page_->initiateLogout(); + }); }); showTransparentOverlayModal(dialog, Qt::AlignCenter); -- cgit 1.5.1