mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-22 15:04:44 +01:00
gui: guard accessing a nullptr 'clientModel'
During shutdown, already queue events dispatched from the backend such 'numConnectionsChanged' and 'networkActiveChanged' could try to access the clientModel object, which might not exist because we manually delete it inside 'BitcoinApplication::requestShutdown()'.
This commit is contained in:
parent
ba907f96ad
commit
f3a612f901
5 changed files with 15 additions and 1 deletions
|
@ -372,6 +372,11 @@ void BitcoinApplication::requestShutdown()
|
|||
// Request node shutdown, which can interrupt long operations, like
|
||||
// rescanning a wallet.
|
||||
node().startShutdown();
|
||||
// Prior to unsetting the client model, stop listening backend signals
|
||||
if (clientModel) {
|
||||
clientModel->stop();
|
||||
}
|
||||
|
||||
// Unsetting the client model can cause the current thread to wait for node
|
||||
// to complete an operation, like wait for a RPC execution to complete.
|
||||
window->setClientModel(nullptr);
|
||||
|
|
|
@ -989,6 +989,7 @@ void BitcoinGUI::gotoLoadPSBT(bool from_clipboard)
|
|||
|
||||
void BitcoinGUI::updateNetworkState()
|
||||
{
|
||||
if (!clientModel) return;
|
||||
int count = clientModel->getNumConnections();
|
||||
QString icon;
|
||||
switch(count)
|
||||
|
|
|
@ -70,7 +70,7 @@ ClientModel::ClientModel(interfaces::Node& node, OptionsModel *_optionsModel, QO
|
|||
subscribeToCoreSignals();
|
||||
}
|
||||
|
||||
ClientModel::~ClientModel()
|
||||
void ClientModel::stop()
|
||||
{
|
||||
unsubscribeFromCoreSignals();
|
||||
|
||||
|
@ -78,6 +78,11 @@ ClientModel::~ClientModel()
|
|||
m_thread->wait();
|
||||
}
|
||||
|
||||
ClientModel::~ClientModel()
|
||||
{
|
||||
stop();
|
||||
}
|
||||
|
||||
int ClientModel::getNumConnections(unsigned int flags) const
|
||||
{
|
||||
ConnectionDirection connections = ConnectionDirection::None;
|
||||
|
|
|
@ -58,6 +58,8 @@ public:
|
|||
explicit ClientModel(interfaces::Node& node, OptionsModel *optionsModel, QObject *parent = nullptr);
|
||||
~ClientModel();
|
||||
|
||||
void stop();
|
||||
|
||||
interfaces::Node& node() const { return m_node; }
|
||||
OptionsModel *getOptionsModel();
|
||||
PeerTableModel *getPeerTableModel();
|
||||
|
|
|
@ -966,6 +966,7 @@ void RPCConsole::message(int category, const QString &message, bool html)
|
|||
|
||||
void RPCConsole::updateNetworkState()
|
||||
{
|
||||
if (!clientModel) return;
|
||||
QString connections = QString::number(clientModel->getNumConnections()) + " (";
|
||||
connections += tr("In:") + " " + QString::number(clientModel->getNumConnections(CONNECTIONS_IN)) + " / ";
|
||||
connections += tr("Out:") + " " + QString::number(clientModel->getNumConnections(CONNECTIONS_OUT)) + ")";
|
||||
|
|
Loading…
Add table
Reference in a new issue