From e2a090f03f1d89d5301c103aaeaafe776688dd0e Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Thu, 10 Mar 2016 02:00:26 +0800 Subject: [PATCH 1/2] Use QAtomicInt to guarantee cleanup() is only executed once --- src/app/application.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/app/application.cpp b/src/app/application.cpp index 9c0d10bc5..ba47515fa 100644 --- a/src/app/application.cpp +++ b/src/app/application.cpp @@ -33,6 +33,7 @@ #include #include #include +#include #ifndef DISABLE_GUI #include "gui/guiiconprovider.h" @@ -548,11 +549,9 @@ void Application::cleanup() #ifndef DISABLE_GUI #ifdef Q_OS_WIN // cleanup() can be called multiple times during shutdown. We only need it once. - static bool alreadyDone = false; - - if (alreadyDone) + static QAtomicInt alreadyDone; + if (!alreadyDone.testAndSetAcquire(0, 1)) return; - alreadyDone = true; #endif // Q_OS_WIN // Hide the window and not leave it on screen as @@ -595,6 +594,7 @@ void Application::cleanup() delete m_fileLogger; Logger::freeInstance(); IconProvider::freeInstance(); + #ifndef DISABLE_GUI #ifdef Q_OS_WIN typedef BOOL (WINAPI *PSHUTDOWNBRDESTROY)(HWND); From f741d3131ddf6ac50ba9e73e4346428a5dc022a5 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Sun, 13 Mar 2016 12:51:27 +0800 Subject: [PATCH 2/2] Delete all mainwindow child widgets. Closes #4871, #5049. Some of the `delete` can be handled by the findChild loop --- src/gui/mainwindow.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/gui/mainwindow.cpp b/src/gui/mainwindow.cpp index 6eb6d1c61..b9dbbb0f8 100644 --- a/src/gui/mainwindow.cpp +++ b/src/gui/mainwindow.cpp @@ -654,12 +654,12 @@ void MainWindow::cleanup() #if (defined(Q_OS_WIN) || defined(Q_OS_MAC)) m_programUpdateTimer->stop(); #endif - delete m_searchFilter; + delete m_searchFilterAction; - delete m_tabs; // this seems enough to also delete all contained widgets - delete m_statusBar; - delete m_pwr; - delete m_toolbarMenu; + + // remove all child widgets + while (QWidget *w = findChild()) + delete w; } void MainWindow::readSettings()