mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-19 06:43:45 +01:00
Merge #11043: Use std::unique_ptr (C++11) where possible
a357293Use MakeUnique<Db>(...) (practicalswift)3e09b39Use MakeUnique<T>(...) instead of std::unique_ptr<T>(new T(...)) (practicalswift)8617989Add MakeUnique (substitute for C++14 std::make_unique) (practicalswift)d223bc9Use unique_ptr for pcoinscatcher/pcoinsdbview/pcoinsTip/pblocktree (practicalswift)b45c597Use unique_ptr for pdbCopy (Db) and fix potential memory leak (practicalswift)29ab96dUse unique_ptr for dbenv (DbEnv) (practicalswift)f72cbf9Use unique_ptr for pfilter (CBloomFilter) (practicalswift)8ccf1bbUse unique_ptr for sem{Addnode,Outbound} (CSemaphore) (practicalswift)73db063Use unique_ptr for upnp_thread (boost::thread) (practicalswift)0024531Use unique_ptr for dbw (CDBWrapper) (practicalswift)fa6d122Use unique_ptr:s for {fee,short,long}Stats (TxConfirmStats) (practicalswift)5a6f768Use unique_ptr for httpRPCTimerInterface (HTTPRPCTimerInterface) (practicalswift)860e912Use unique_ptr for pwalletMain (CWallet) (practicalswift) Pull request description: Use `std::unique_ptr` (C++11) where possible. Rationale: 1. Avoid resource leaks (specifically: forgetting to `delete` an object created using `new`) 2. Avoid undefined behaviour (specifically: double `delete`:s) **Note to reviewers:** Please let me know if I've missed any obvious `std::unique_ptr` candidates. Hopefully this PR should cover all the trivial cases. Tree-SHA512: 9fbeb47b800ab8ff4e0be9f2a22ab63c23d5c613a0c6716d9183db8d22ddbbce592fb8384a8b7874bf7375c8161efb13ca2197ad6f24b75967148037f0f7b20c
This commit is contained in:
@@ -2102,7 +2102,7 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
|
||||
|
||||
if (!AlreadyHave(inv) &&
|
||||
AcceptToMemoryPool(mempool, state, ptx, &fMissingInputs, &lRemovedTxn, false /* bypass_limits */, 0 /* nAbsurdFee */)) {
|
||||
mempool.check(pcoinsTip);
|
||||
mempool.check(pcoinsTip.get());
|
||||
RelayTransaction(tx, connman);
|
||||
for (unsigned int i = 0; i < tx.vout.size(); i++) {
|
||||
vWorkQueue.emplace_back(inv.hash, i);
|
||||
@@ -2169,7 +2169,7 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
|
||||
recentRejects->insert(orphanHash);
|
||||
}
|
||||
}
|
||||
mempool.check(pcoinsTip);
|
||||
mempool.check(pcoinsTip.get());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2751,8 +2751,7 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
|
||||
else
|
||||
{
|
||||
LOCK(pfrom->cs_filter);
|
||||
delete pfrom->pfilter;
|
||||
pfrom->pfilter = new CBloomFilter(filter);
|
||||
pfrom->pfilter.reset(new CBloomFilter(filter));
|
||||
pfrom->pfilter->UpdateEmptyFull();
|
||||
pfrom->fRelayTxes = true;
|
||||
}
|
||||
@@ -2788,8 +2787,7 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
|
||||
{
|
||||
LOCK(pfrom->cs_filter);
|
||||
if (pfrom->GetLocalServices() & NODE_BLOOM) {
|
||||
delete pfrom->pfilter;
|
||||
pfrom->pfilter = new CBloomFilter();
|
||||
pfrom->pfilter.reset(new CBloomFilter());
|
||||
}
|
||||
pfrom->fRelayTxes = true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user