File tree Expand file tree Collapse file tree 1 file changed +8
-2
lines changed
Expand file tree Collapse file tree 1 file changed +8
-2
lines changed Original file line number Diff line number Diff line change @@ -4012,7 +4012,10 @@ CWallet* CWallet::CreateWalletFromFile(const std::string& name, const fs::path&
40124012
40134013 int64_t nStart = GetTimeMillis ();
40144014 bool fFirstRun = true ;
4015- CWallet *walletInstance = new CWallet (name, WalletDatabase::Create (path));
4015+ // Make a temporary wallet unique pointer so memory doesn't get leaked if
4016+ // wallet creation fails.
4017+ auto temp_wallet = MakeUnique<CWallet>(name, WalletDatabase::Create (path));
4018+ CWallet* walletInstance = temp_wallet.get ();
40164019 DBErrors nLoadWalletRet = walletInstance->LoadWallet (fFirstRun );
40174020 if (nLoadWalletRet != DBErrors::LOAD_OK)
40184021 {
@@ -4224,7 +4227,6 @@ CWallet* CWallet::CreateWalletFromFile(const std::string& name, const fs::path&
42244227 }
42254228
42264229 walletInstance->m_last_block_processed = chainActive.Tip ();
4227- RegisterValidationInterface (walletInstance);
42284230
42294231 if (chainActive.Tip () && chainActive.Tip () != pindexRescan)
42304232 {
@@ -4290,6 +4292,10 @@ CWallet* CWallet::CreateWalletFromFile(const std::string& name, const fs::path&
42904292 }
42914293 }
42924294 }
4295+
4296+ // Register with the validation interface. It's ok to do this after rescan since we're still holding cs_main.
4297+ RegisterValidationInterface (temp_wallet.release ());
4298+
42934299 walletInstance->SetBroadcastTransactions (gArgs .GetBoolArg (" -walletbroadcast" , DEFAULT_WALLETBROADCAST));
42944300
42954301 {
You can’t perform that action at this time.
0 commit comments