Skip to content

Commit 20763f1

Browse files
committed
merge bitcoin-core/gui#835: Fix crash when closing wallet
1 parent b47b1f6 commit 20763f1

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

src/qt/walletcontroller.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,14 @@ std::map<std::string, bool> WalletController::listWalletDir() const
7777
return wallets;
7878
}
7979

80+
void WalletController::removeWallet(WalletModel* wallet_model)
81+
{
82+
// Once the wallet is successfully removed from the node, the model will emit the 'WalletModel::unload' signal.
83+
// This signal is already connected and will complete the removal of the view from the GUI.
84+
// Look at 'WalletController::getOrCreateWallet' for the signal connection.
85+
wallet_model->wallet().remove();
86+
}
87+
8088
void WalletController::closeWallet(WalletModel* wallet_model, QWidget* parent)
8189
{
8290
QMessageBox box(parent);
@@ -87,10 +95,7 @@ void WalletController::closeWallet(WalletModel* wallet_model, QWidget* parent)
8795
box.setDefaultButton(QMessageBox::Yes);
8896
if (box.exec() != QMessageBox::Yes) return;
8997

90-
// First remove wallet from node.
91-
wallet_model->wallet().remove();
92-
// Now release the model.
93-
removeAndDeleteWallet(wallet_model);
98+
removeWallet(wallet_model);
9499
}
95100

96101
void WalletController::closeAllWallets(QWidget* parent)
@@ -103,11 +108,8 @@ void WalletController::closeAllWallets(QWidget* parent)
103108

104109
QMutexLocker locker(&m_mutex);
105110
for (WalletModel* wallet_model : m_wallets) {
106-
wallet_model->wallet().remove();
107-
Q_EMIT walletRemoved(wallet_model);
108-
delete wallet_model;
111+
removeWallet(wallet_model);
109112
}
110-
m_wallets.clear();
111113
}
112114

113115
WalletModel* WalletController::getOrCreateWallet(std::unique_ptr<interfaces::Wallet> wallet)

src/qt/walletcontroller.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ class WalletController : public QObject
8282
std::unique_ptr<interfaces::Handler> m_handler_load_wallet;
8383

8484
friend class WalletControllerActivity;
85+
86+
//! Starts the wallet closure procedure
87+
void removeWallet(WalletModel* wallet_model);
8588
};
8689

8790
class WalletControllerActivity : public QObject

0 commit comments

Comments
 (0)