Skip to content

Commit 5204598

Browse files
committed
qt: Avoid shutdownwindow-related memory leak
Store a reference to the shutdown window on BitcoinApplication, so that it will be deleted when exiting the main loop.
1 parent e4f126a commit 5204598

File tree

3 files changed

+6
-7
lines changed

3 files changed

+6
-7
lines changed

src/qt/bitcoin.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ public Q_SLOTS:
245245
#endif
246246
int returnValue;
247247
const PlatformStyle *platformStyle;
248+
std::unique_ptr<QWidget> shutdownWindow;
248249

249250
void startThread();
250251
};
@@ -411,7 +412,7 @@ void BitcoinApplication::requestShutdown()
411412
// Show a simple window indicating shutdown status
412413
// Do this first as some of the steps may take some time below,
413414
// for example the RPC console may still be executing a command.
414-
ShutdownWindow::showShutdownWindow(window);
415+
shutdownWindow.reset(ShutdownWindow::showShutdownWindow(window));
415416

416417
qDebug() << __func__ << ": Requesting shutdown";
417418
startThread();

src/qt/utilitydialog.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -171,22 +171,20 @@ ShutdownWindow::ShutdownWindow(QWidget *parent, Qt::WindowFlags f):
171171
setLayout(layout);
172172
}
173173

174-
void ShutdownWindow::showShutdownWindow(BitcoinGUI *window)
174+
QWidget *ShutdownWindow::showShutdownWindow(BitcoinGUI *window)
175175
{
176176
if (!window)
177-
return;
177+
return nullptr;
178178

179179
// Show a simple window indicating shutdown status
180180
QWidget *shutdownWindow = new ShutdownWindow();
181-
// We don't hold a direct pointer to the shutdown window after creation, so use
182-
// Qt::WA_DeleteOnClose to make sure that the window will be deleted eventually.
183-
shutdownWindow->setAttribute(Qt::WA_DeleteOnClose);
184181
shutdownWindow->setWindowTitle(window->windowTitle());
185182

186183
// Center shutdown window at where main window was
187184
const QPoint global = window->mapToGlobal(window->rect().center());
188185
shutdownWindow->move(global.x() - shutdownWindow->width() / 2, global.y() - shutdownWindow->height() / 2);
189186
shutdownWindow->show();
187+
return shutdownWindow;
190188
}
191189

192190
void ShutdownWindow::closeEvent(QCloseEvent *event)

src/qt/utilitydialog.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class ShutdownWindow : public QWidget
4343

4444
public:
4545
ShutdownWindow(QWidget *parent=0, Qt::WindowFlags f=0);
46-
static void showShutdownWindow(BitcoinGUI *window);
46+
static QWidget *showShutdownWindow(BitcoinGUI *window);
4747

4848
protected:
4949
void closeEvent(QCloseEvent *event);

0 commit comments

Comments
 (0)