Skip to content

Commit

Permalink
Cancel wallet balance timer when shutdown requested
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ryanofsky committed May 1, 2020
1 parent 83f69fa commit 2bc9b92
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
12 changes: 9 additions & 3 deletions src/qt/walletmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,15 @@
WalletModel::WalletModel(std::unique_ptr<interfaces::Wallet> wallet, ClientModel& client_model, const PlatformStyle *platformStyle, QObject *parent) :
QObject(parent),
m_wallet(std::move(wallet)),
m_client_model(client_model),
m_client_model(&client_model),
m_node(client_model.node()),
optionsModel(client_model.getOptionsModel()),
addressTableModel(nullptr),
transactionTableModel(nullptr),
recentRequestsTableModel(nullptr),
cachedEncryptionStatus(Unencrypted),
cachedNumBlocks(0)
cachedNumBlocks(0),
timer(new QTimer(this))
{
fHaveWatchOnly = m_wallet->haveWatchOnly();
addressTableModel = new AddressTableModel(this);
Expand All @@ -63,11 +64,16 @@ WalletModel::~WalletModel()
void WalletModel::startPollBalance()
{
// This timer will be fired repeatedly to update the balance
QTimer* timer = new QTimer(this);
connect(timer, &QTimer::timeout, this, &WalletModel::pollBalanceChanged);
timer->start(MODEL_UPDATE_DELAY);
}

void WalletModel::setClientModel(ClientModel* client_model)
{
m_client_model = client_model;
if (!m_client_model) timer->stop();
}

void WalletModel::updateStatus()
{
EncryptionStatus newEncryptionStatus = getEncryptionStatus();
Expand Down
4 changes: 3 additions & 1 deletion src/qt/walletmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ class WalletModel : public QObject

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

QString getWalletName() const;
Expand All @@ -161,7 +162,7 @@ class WalletModel : public QObject
std::unique_ptr<interfaces::Handler> m_handler_show_progress;
std::unique_ptr<interfaces::Handler> m_handler_watch_only_changed;
std::unique_ptr<interfaces::Handler> m_handler_can_get_addrs_changed;
ClientModel& m_client_model;
ClientModel* m_client_model;
interfaces::Node& m_node;

bool fHaveWatchOnly;
Expand All @@ -179,6 +180,7 @@ class WalletModel : public QObject
interfaces::WalletBalances m_cached_balances;
EncryptionStatus cachedEncryptionStatus;
int cachedNumBlocks;
QTimer* timer;

void subscribeToCoreSignals();
void unsubscribeFromCoreSignals();
Expand Down
1 change: 1 addition & 0 deletions src/qt/walletview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ void WalletView::setClientModel(ClientModel *_clientModel)

overviewPage->setClientModel(_clientModel);
sendCoinsPage->setClientModel(_clientModel);
if (walletModel) walletModel->setClientModel(_clientModel);
}

void WalletView::setWalletModel(WalletModel *_walletModel)
Expand Down

0 comments on commit 2bc9b92

Please sign in to comment.