Skip to content

Commit db5e22e

Browse files
committed
Merge #9190: qt: Plug many memory leaks
ed998ea qt: Avoid OpenSSL certstore-related memory leak (Wladimir J. van der Laan) 5204598 qt: Avoid shutdownwindow-related memory leak (Wladimir J. van der Laan) e4f126a qt: Avoid splash-screen related memory leak (Wladimir J. van der Laan) 693384e qt: Prevent thread/memory leak on exiting RPCConsole (Wladimir J. van der Laan) 47db075 qt: Plug many memory leaks (Wladimir J. van der Laan)
2 parents 93566e0 + ed998ea commit db5e22e

23 files changed

+102
-74
lines changed

src/qt/addressbookpage.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ AddressBookPage::AddressBookPage(const PlatformStyle *platformStyle, Mode _mode,
8383
deleteAction = new QAction(ui->deleteAddress->text(), this);
8484

8585
// Build context menu
86-
contextMenu = new QMenu();
86+
contextMenu = new QMenu(this);
8787
contextMenu->addAction(copyAddressAction);
8888
contextMenu->addAction(copyLabelAction);
8989
contextMenu->addAction(editAction);

src/qt/bantablemodel.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,19 @@ BanTableModel::BanTableModel(ClientModel *parent) :
8787
clientModel(parent)
8888
{
8989
columns << tr("IP/Netmask") << tr("Banned Until");
90-
priv = new BanTablePriv();
90+
priv.reset(new BanTablePriv());
9191
// default to unsorted
9292
priv->sortColumn = -1;
9393

9494
// load initial data
9595
refresh();
9696
}
9797

98+
BanTableModel::~BanTableModel()
99+
{
100+
// Intentionally left empty
101+
}
102+
98103
int BanTableModel::rowCount(const QModelIndex &parent) const
99104
{
100105
Q_UNUSED(parent);

src/qt/bantablemodel.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class BanTableModel : public QAbstractTableModel
4040

4141
public:
4242
explicit BanTableModel(ClientModel *parent = 0);
43+
~BanTableModel();
4344
void startAutoRefresh();
4445
void stopAutoRefresh();
4546

@@ -66,7 +67,7 @@ public Q_SLOTS:
6667
private:
6768
ClientModel *clientModel;
6869
QStringList columns;
69-
BanTablePriv *priv;
70+
std::unique_ptr<BanTablePriv> priv;
7071
};
7172

7273
#endif // BITCOIN_QT_BANTABLEMODEL_H

src/qt/bitcoin.cpp

Lines changed: 8 additions & 6 deletions
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
};
@@ -365,9 +366,8 @@ void BitcoinApplication::createWindow(const NetworkStyle *networkStyle)
365366
void BitcoinApplication::createSplashScreen(const NetworkStyle *networkStyle)
366367
{
367368
SplashScreen *splash = new SplashScreen(0, networkStyle);
368-
// We don't hold a direct pointer to the splash screen after creation, so use
369-
// Qt::WA_DeleteOnClose to make sure that the window will be deleted eventually.
370-
splash->setAttribute(Qt::WA_DeleteOnClose);
369+
// We don't hold a direct pointer to the splash screen after creation, but the splash
370+
// screen will take care of deleting itself when slotFinish happens.
371371
splash->show();
372372
connect(this, SIGNAL(splashFinished(QWidget*)), splash, SLOT(slotFinish(QWidget*)));
373373
connect(this, SIGNAL(requestedShutdown()), splash, SLOT(close()));
@@ -409,6 +409,11 @@ void BitcoinApplication::requestInitialize()
409409

410410
void BitcoinApplication::requestShutdown()
411411
{
412+
// Show a simple window indicating shutdown status
413+
// Do this first as some of the steps may take some time below,
414+
// for example the RPC console may still be executing a command.
415+
shutdownWindow.reset(ShutdownWindow::showShutdownWindow(window));
416+
412417
qDebug() << __func__ << ": Requesting shutdown";
413418
startThread();
414419
window->hide();
@@ -423,9 +428,6 @@ void BitcoinApplication::requestShutdown()
423428
delete clientModel;
424429
clientModel = 0;
425430

426-
// Show a simple window indicating shutdown status
427-
ShutdownWindow::showShutdownWindow(window);
428-
429431
// Request shutdown from core thread
430432
Q_EMIT requestedShutdown();
431433
}

src/qt/bitcoingui.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,13 @@ void BitcoinGUI::setClientModel(ClientModel *_clientModel)
511511
// Disable context menu on tray icon
512512
trayIconMenu->clear();
513513
}
514+
// Propagate cleared model to child objects
515+
rpcConsole->setClientModel(nullptr);
516+
#ifdef ENABLE_WALLET
517+
walletFrame->setClientModel(nullptr);
518+
#endif // ENABLE_WALLET
519+
unitDisplayControl->setOptionsModel(nullptr);
520+
connectionsControl->setClientModel(nullptr);
514521
}
515522
}
516523

@@ -1191,7 +1198,7 @@ void UnitDisplayStatusBarControl::mousePressEvent(QMouseEvent *event)
11911198
/** Creates context menu, its actions, and wires up all the relevant signals for mouse events. */
11921199
void UnitDisplayStatusBarControl::createContextMenu()
11931200
{
1194-
menu = new QMenu();
1201+
menu = new QMenu(this);
11951202
Q_FOREACH(BitcoinUnits::Unit u, BitcoinUnits::availableUnits())
11961203
{
11971204
QAction *menuAction = new QAction(QString(BitcoinUnits::name(u)), this);
@@ -1248,7 +1255,5 @@ void NetworkToggleStatusBarControl::mousePressEvent(QMouseEvent *event)
12481255
/** Lets the control know about the Client Model */
12491256
void NetworkToggleStatusBarControl::setClientModel(ClientModel *_clientModel)
12501257
{
1251-
if (_clientModel) {
1252-
this->clientModel = _clientModel;
1253-
}
1258+
this->clientModel = _clientModel;
12541259
}

src/qt/coincontroldialog.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ CoinControlDialog::CoinControlDialog(const PlatformStyle *_platformStyle, QWidge
5959
unlockAction = new QAction(tr("Unlock unspent"), this); // we need to enable/disable this
6060

6161
// context menu
62-
contextMenu = new QMenu();
62+
contextMenu = new QMenu(this);
6363
contextMenu->addAction(copyAddressAction);
6464
contextMenu->addAction(copyLabelAction);
6565
contextMenu->addAction(copyAmountAction);

src/qt/guiutil.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,8 @@ void TableViewLastColumnResizingFixer::on_geometriesChanged()
585585
* Initializes all internal variables and prepares the
586586
* the resize modes of the last 2 columns of the table and
587587
*/
588-
TableViewLastColumnResizingFixer::TableViewLastColumnResizingFixer(QTableView* table, int lastColMinimumWidth, int allColsMinimumWidth) :
588+
TableViewLastColumnResizingFixer::TableViewLastColumnResizingFixer(QTableView* table, int lastColMinimumWidth, int allColsMinimumWidth, QObject *parent) :
589+
QObject(parent),
589590
tableView(table),
590591
lastColumnMinimumWidth(lastColMinimumWidth),
591592
allColumnsMinimumWidth(allColsMinimumWidth)

src/qt/guiutil.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ namespace GUIUtil
149149
Q_OBJECT
150150

151151
public:
152-
TableViewLastColumnResizingFixer(QTableView* table, int lastColMinimumWidth, int allColsMinimumWidth);
152+
TableViewLastColumnResizingFixer(QTableView* table, int lastColMinimumWidth, int allColsMinimumWidth, QObject *parent);
153153
void stretchColumnWidth(int column);
154154

155155
private:

src/qt/overviewpage.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ class TxViewDelegate : public QAbstractItemDelegate
2525
{
2626
Q_OBJECT
2727
public:
28-
TxViewDelegate(const PlatformStyle *_platformStyle):
29-
QAbstractItemDelegate(), unit(BitcoinUnits::BTC),
28+
TxViewDelegate(const PlatformStyle *_platformStyle, QObject *parent=nullptr):
29+
QAbstractItemDelegate(parent), unit(BitcoinUnits::BTC),
3030
platformStyle(_platformStyle)
3131
{
3232

@@ -119,8 +119,7 @@ OverviewPage::OverviewPage(const PlatformStyle *platformStyle, QWidget *parent)
119119
currentWatchOnlyBalance(-1),
120120
currentWatchUnconfBalance(-1),
121121
currentWatchImmatureBalance(-1),
122-
txdelegate(new TxViewDelegate(platformStyle)),
123-
filter(0)
122+
txdelegate(new TxViewDelegate(platformStyle, this))
124123
{
125124
ui->setupUi(this);
126125

@@ -220,15 +219,15 @@ void OverviewPage::setWalletModel(WalletModel *model)
220219
if(model && model->getOptionsModel())
221220
{
222221
// Set up transaction list
223-
filter = new TransactionFilterProxy();
222+
filter.reset(new TransactionFilterProxy());
224223
filter->setSourceModel(model->getTransactionTableModel());
225224
filter->setLimit(NUM_ITEMS);
226225
filter->setDynamicSortFilter(true);
227226
filter->setSortRole(Qt::EditRole);
228227
filter->setShowInactive(false);
229228
filter->sort(TransactionTableModel::Date, Qt::DescendingOrder);
230229

231-
ui->listTransactions->setModel(filter);
230+
ui->listTransactions->setModel(filter.get());
232231
ui->listTransactions->setModelColumn(TransactionTableModel::ToAddress);
233232

234233
// Keep up to date with wallet

src/qt/overviewpage.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "amount.h"
99

1010
#include <QWidget>
11+
#include <memory>
1112

1213
class ClientModel;
1314
class TransactionFilterProxy;
@@ -56,7 +57,7 @@ public Q_SLOTS:
5657
CAmount currentWatchImmatureBalance;
5758

5859
TxViewDelegate *txdelegate;
59-
TransactionFilterProxy *filter;
60+
std::unique_ptr<TransactionFilterProxy> filter;
6061

6162
private Q_SLOTS:
6263
void updateDisplayUnit();

0 commit comments

Comments
 (0)