Skip to content

Commit 3c13c74

Browse files
committed
[Stealth] Fix get wallet db dangling pointer
1 parent cd060bb commit 3c13c74

File tree

2 files changed

+12
-16
lines changed

2 files changed

+12
-16
lines changed

src/wallet/db.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -424,8 +424,6 @@ bool CDB::Rewrite(const std::string& strFile, const char* pszSkip)
424424
return fSuccess;
425425
}
426426
}
427-
// TODO (BDAP): Why is this needed? Worked without before adding stealth
428-
--bitdb.mapFileUseCount[strFile];
429427
MilliSleep(100);
430428
}
431429
return false;

src/wallet/wallet.cpp

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5434,11 +5434,11 @@ inline bool MatchPrefix(uint32_t nAddrBits, uint32_t addrPrefix, uint32_t output
54345434
bool CWallet::ProcessStealthQueue()
54355435
{
54365436
CWalletDB* pwdb = GetWalletDB();
5437-
if (!pwdb)
5438-
return false;
54395437

5440-
if (IsLocked())
5438+
if (IsLocked()) {
5439+
delete pwdb;
54415440
return false;
5441+
}
54425442

54435443
for (const std::pair<CKeyID, CStealthKeyQueueData>& data : vStealthKeyQueue) {
54445444
CStealthKeyQueueData stealthData = data.second;
@@ -5472,6 +5472,7 @@ bool CWallet::ProcessStealthQueue()
54725472
}
54735473
// TODO (Stealth): Add lock for vector.
54745474
vStealthKeyQueue.clear();
5475+
delete pwdb;
54755476
return true;
54765477
}
54775478

@@ -5486,8 +5487,6 @@ bool RunProcessStealthQueue()
54865487
bool CWallet::ProcessStealthOutput(const CTxDestination& address, std::vector<uint8_t>& vchEphemPK, uint32_t prefix, bool fHavePrefix, CKey& sShared)
54875488
{
54885489
CWalletDB* pwdb = GetWalletDB();
5489-
if (!pwdb)
5490-
return false;
54915490

54925491
CKeyID idMatchShared = boost::get<CKeyID>(address);
54935492
ec_point pkExtracted;
@@ -5532,15 +5531,18 @@ bool CWallet::ProcessStealthOutput(const CTxDestination& address, std::vector<ui
55325531
CStealthKeyQueueData lockedSkQueueData(cpkEphem, cpkScan, cpkSpend, sShared);
55335532
if (!pwdb->WriteStealthKeyQueue(idMatchShared, lockedSkQueueData)) {
55345533
LogPrintf("%s: Error WriteStealthKeyQueue failed for %s.\n", __func__, CDynamicAddress(idExtracted).ToString());
5534+
delete pwdb;
55355535
return false;
55365536
}
55375537
vStealthKeyQueue.push_back(std::make_pair(cpkSpend.GetID(), lockedSkQueueData));
55385538
nFoundStealth++;
5539+
delete pwdb;
55395540
return true;
55405541
}
55415542

55425543
if (!GetKey(sxAddr.GetSpendKeyID(), sSpend)) {
55435544
LogPrintf("%s: Error getting spend private key (%s) for stealth transaction.\n", __func__, CDynamicAddress(sxAddr.GetSpendKeyID()).ToString());
5545+
delete pwdb;
55445546
return false;
55455547
}
55465548
CKey sSpendR;
@@ -5563,8 +5565,10 @@ bool CWallet::ProcessStealthOutput(const CTxDestination& address, std::vector<ui
55635565
continue;
55645566
}
55655567
nFoundStealth++;
5568+
delete pwdb;
55665569
return true;
55675570
}
5571+
delete pwdb;
55685572
return false;
55695573
}
55705574

@@ -5717,14 +5721,14 @@ bool CWallet::AddStealthAddress(const CStealthAddress& sxAddr, const CKey& skSpe
57175721
{
57185722
LogPrintf("%s: %s\n", __func__, sxAddr.Encoded());
57195723
CWalletDB* pwdb = GetWalletDB();
5720-
if (!pwdb)
5721-
return false;
57225724

57235725
LOCK(cs_wallet);
57245726
if (!pwdb->WriteStealthAddress(sxAddr)) {
5727+
delete pwdb;
57255728
return error("%s: WriteStealthAddress failed.", __func__);
57265729
}
57275730
mapstealthAddresses[sxAddr.GetSpendKeyID()] = sxAddr;
5731+
delete pwdb;
57285732
return true;
57295733
}
57305734

@@ -5742,13 +5746,7 @@ bool CWallet::AddToStealthQueue(const std::pair<CKeyID, CStealthKeyQueueData>& p
57425746

57435747
CWalletDB* CWallet::GetWalletDB()
57445748
{
5745-
CWalletDB* pwdb;
5746-
if (IsCrypted() && pwalletdbEncryption) {
5747-
pwdb = pwalletdbEncryption;
5748-
}
5749-
else {
5750-
pwdb = new CWalletDB(strWalletFile, "r+");
5751-
}
5749+
CWalletDB* pwdb = new CWalletDB(strWalletFile, "r+");
57525750
assert(pwdb);
57535751
return pwdb;
57545752
}

0 commit comments

Comments
 (0)