Fix a use-after-free error during logout

pull/1/head
Konstantinos Sideris 6 years ago
parent b10e1bafc8
commit e29fceaee4
  1. 37
      src/ChatPage.cpp
  2. 1
      src/ChatPage.h
  3. 15
      src/MainWindow.cpp
  4. 2
      src/MainWindow.h
  5. 4
      src/UserInfoWidget.cpp
  6. 3
      src/UserInfoWidget.h

@ -169,24 +169,6 @@ ChatPage::ChatPage(QSharedPointer<UserSettings> userSettings, QWidget *parent)
});
connect(this, &ChatPage::loggedOut, this, &ChatPage::logout);
connect(user_info_widget_, &UserInfoWidget::logout, this, [this]() {
http::client()->logout(
[this](const mtx::responses::Logout &, mtx::http::RequestErr err) {
if (err) {
// TODO: handle special errors
emit contentLoaded();
nhlog::net()->warn(
"failed to logout: {} - {}",
mtx::errors::to_string(err->matrix_error.errcode),
err->matrix_error.error);
return;
}
emit loggedOut();
});
emit showOverlayProgressBar();
});
connect(top_bar_, &TopRoomBar::showRoomList, splitter, &Splitter::showFullRoomList);
connect(top_bar_, &TopRoomBar::inviteUsers, this, [this](QStringList users) {
@ -1332,3 +1314,22 @@ ChatPage::isSideBarExpanded()
{
return sideBar_->size().width() > ui::sidebar::NormalSize;
}
void
ChatPage::initiateLogout()
{
http::client()->logout([this](const mtx::responses::Logout &, mtx::http::RequestErr err) {
if (err) {
// TODO: handle special errors
emit contentLoaded();
nhlog::net()->warn("failed to logout: {} - {}",
mtx::errors::to_string(err->matrix_error.errcode),
err->matrix_error.error);
return;
}
emit loggedOut();
});
emit showOverlayProgressBar();
}

@ -72,6 +72,7 @@ public:
void hideSideBars();
//! Show the room/group list (if it was visible).
void showSideBars();
void initiateLogout();
public slots:
void leaveRoom(const QString &room_id);

@ -441,15 +441,22 @@ MainWindow::showSolidOverlayModal(QWidget *content, QFlags<Qt::AlignmentFlag> fl
}
void
MainWindow::openLogoutDialog(std::function<void()> 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);

@ -70,7 +70,7 @@ public:
void openCreateRoomDialog(
std::function<void(const mtx::requests::CreateRoom &request)> callback);
void openJoinRoomDialog(std::function<void(const QString &room_id)> callback);
void openLogoutDialog(std::function<void()> callback);
void openLogoutDialog();
void openRoomSettings(const QString &room_id = "");
void openMemberListDialog(const QString &room_id = "");
void openUserProfile(const QString &user_id, const QString &room_id);

@ -89,8 +89,8 @@ UserInfoWidget::UserInfoWidget(QWidget *parent)
topLayout_->addLayout(buttonLayout_);
// Show the confirmation dialog.
connect(logoutButton_, &QPushButton::clicked, this, [this]() {
MainWindow::instance()->openLogoutDialog([this]() { emit logout(); });
connect(logoutButton_, &QPushButton::clicked, this, []() {
MainWindow::instance()->openLogoutDialog();
});
}

@ -42,9 +42,6 @@ public:
QColor borderColor() const { return borderColor_; }
void setBorderColor(QColor &color) { borderColor_ = color; }
signals:
void logout();
protected:
void resizeEvent(QResizeEvent *event) override;
void paintEvent(QPaintEvent *event) override;

Loading…
Cancel
Save