Skip to content

Commit 2bc9b92

Browse files
committed
Cancel wallet balance timer when shutdown requested
This doesn't fix any current problem, but it makes balance checking code less fragile, and prevents use-after free travis error in next commit: https://travis-ci.org/github/bitcoin/bitcoin/jobs/675367629#L4240
1 parent 83f69fa commit 2bc9b92

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

src/qt/walletmodel.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,15 @@
3838
WalletModel::WalletModel(std::unique_ptr<interfaces::Wallet> wallet, ClientModel& client_model, const PlatformStyle *platformStyle, QObject *parent) :
3939
QObject(parent),
4040
m_wallet(std::move(wallet)),
41-
m_client_model(client_model),
41+
m_client_model(&client_model),
4242
m_node(client_model.node()),
4343
optionsModel(client_model.getOptionsModel()),
4444
addressTableModel(nullptr),
4545
transactionTableModel(nullptr),
4646
recentRequestsTableModel(nullptr),
4747
cachedEncryptionStatus(Unencrypted),
48-
cachedNumBlocks(0)
48+
cachedNumBlocks(0),
49+
timer(new QTimer(this))
4950
{
5051
fHaveWatchOnly = m_wallet->haveWatchOnly();
5152
addressTableModel = new AddressTableModel(this);
@@ -63,11 +64,16 @@ WalletModel::~WalletModel()
6364
void WalletModel::startPollBalance()
6465
{
6566
// This timer will be fired repeatedly to update the balance
66-
QTimer* timer = new QTimer(this);
6767
connect(timer, &QTimer::timeout, this, &WalletModel::pollBalanceChanged);
6868
timer->start(MODEL_UPDATE_DELAY);
6969
}
7070

71+
void WalletModel::setClientModel(ClientModel* client_model)
72+
{
73+
m_client_model = client_model;
74+
if (!m_client_model) timer->stop();
75+
}
76+
7177
void WalletModel::updateStatus()
7278
{
7379
EncryptionStatus newEncryptionStatus = getEncryptionStatus();

src/qt/walletmodel.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ class WalletModel : public QObject
144144

145145
interfaces::Node& node() const { return m_node; }
146146
interfaces::Wallet& wallet() const { return *m_wallet; }
147+
void setClientModel(ClientModel* client_model);
147148
int getNumBlocks() const { return cachedNumBlocks; }
148149

149150
QString getWalletName() const;
@@ -161,7 +162,7 @@ class WalletModel : public QObject
161162
std::unique_ptr<interfaces::Handler> m_handler_show_progress;
162163
std::unique_ptr<interfaces::Handler> m_handler_watch_only_changed;
163164
std::unique_ptr<interfaces::Handler> m_handler_can_get_addrs_changed;
164-
ClientModel& m_client_model;
165+
ClientModel* m_client_model;
165166
interfaces::Node& m_node;
166167

167168
bool fHaveWatchOnly;
@@ -179,6 +180,7 @@ class WalletModel : public QObject
179180
interfaces::WalletBalances m_cached_balances;
180181
EncryptionStatus cachedEncryptionStatus;
181182
int cachedNumBlocks;
183+
QTimer* timer;
182184

183185
void subscribeToCoreSignals();
184186
void unsubscribeFromCoreSignals();

src/qt/walletview.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ void WalletView::setClientModel(ClientModel *_clientModel)
9797

9898
overviewPage->setClientModel(_clientModel);
9999
sendCoinsPage->setClientModel(_clientModel);
100+
if (walletModel) walletModel->setClientModel(_clientModel);
100101
}
101102

102103
void WalletView::setWalletModel(WalletModel *_walletModel)

0 commit comments

Comments
 (0)