Skip to content

Commit f3a612f

Browse files
committed
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()'.
1 parent ba907f9 commit f3a612f

File tree

5 files changed

+15
-1
lines changed

5 files changed

+15
-1
lines changed

src/qt/bitcoin.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,11 @@ void BitcoinApplication::requestShutdown()
372372
// Request node shutdown, which can interrupt long operations, like
373373
// rescanning a wallet.
374374
node().startShutdown();
375+
// Prior to unsetting the client model, stop listening backend signals
376+
if (clientModel) {
377+
clientModel->stop();
378+
}
379+
375380
// Unsetting the client model can cause the current thread to wait for node
376381
// to complete an operation, like wait for a RPC execution to complete.
377382
window->setClientModel(nullptr);

src/qt/bitcoingui.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -989,6 +989,7 @@ void BitcoinGUI::gotoLoadPSBT(bool from_clipboard)
989989

990990
void BitcoinGUI::updateNetworkState()
991991
{
992+
if (!clientModel) return;
992993
int count = clientModel->getNumConnections();
993994
QString icon;
994995
switch(count)

src/qt/clientmodel.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,19 @@ ClientModel::ClientModel(interfaces::Node& node, OptionsModel *_optionsModel, QO
7070
subscribeToCoreSignals();
7171
}
7272

73-
ClientModel::~ClientModel()
73+
void ClientModel::stop()
7474
{
7575
unsubscribeFromCoreSignals();
7676

7777
m_thread->quit();
7878
m_thread->wait();
7979
}
8080

81+
ClientModel::~ClientModel()
82+
{
83+
stop();
84+
}
85+
8186
int ClientModel::getNumConnections(unsigned int flags) const
8287
{
8388
ConnectionDirection connections = ConnectionDirection::None;

src/qt/clientmodel.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ class ClientModel : public QObject
5858
explicit ClientModel(interfaces::Node& node, OptionsModel *optionsModel, QObject *parent = nullptr);
5959
~ClientModel();
6060

61+
void stop();
62+
6163
interfaces::Node& node() const { return m_node; }
6264
OptionsModel *getOptionsModel();
6365
PeerTableModel *getPeerTableModel();

src/qt/rpcconsole.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -966,6 +966,7 @@ void RPCConsole::message(int category, const QString &message, bool html)
966966

967967
void RPCConsole::updateNetworkState()
968968
{
969+
if (!clientModel) return;
969970
QString connections = QString::number(clientModel->getNumConnections()) + " (";
970971
connections += tr("In:") + " " + QString::number(clientModel->getNumConnections(CONNECTIONS_IN)) + " / ";
971972
connections += tr("Out:") + " " + QString::number(clientModel->getNumConnections(CONNECTIONS_OUT)) + ")";

0 commit comments

Comments
 (0)