mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-11 06:28:31 +01:00
miner: Avoid stack-use-after-return in validationinterface
This is achieved by switching to a shared_ptr. Also, switch the validationinterfaces in the tests to use shared_ptrs for the same reason.
This commit is contained in:
@@ -32,7 +32,7 @@ struct MinerTestingSetup : public RegTestingSetup {
|
||||
|
||||
BOOST_FIXTURE_TEST_SUITE(validation_block_tests, MinerTestingSetup)
|
||||
|
||||
struct TestSubscriber : public CValidationInterface {
|
||||
struct TestSubscriber final : public CValidationInterface {
|
||||
uint256 m_expected_tip;
|
||||
|
||||
explicit TestSubscriber(uint256 tip) : m_expected_tip(tip) {}
|
||||
@@ -175,8 +175,8 @@ BOOST_AUTO_TEST_CASE(processnewblock_signals_ordering)
|
||||
LOCK(cs_main);
|
||||
initial_tip = ::ChainActive().Tip();
|
||||
}
|
||||
TestSubscriber sub(initial_tip->GetBlockHash());
|
||||
RegisterValidationInterface(&sub);
|
||||
auto sub = std::make_shared<TestSubscriber>(initial_tip->GetBlockHash());
|
||||
RegisterSharedValidationInterface(sub);
|
||||
|
||||
// create a bunch of threads that repeatedly process a block generated above at random
|
||||
// this will create parallelism and randomness inside validation - the ValidationInterface
|
||||
@@ -206,10 +206,10 @@ BOOST_AUTO_TEST_CASE(processnewblock_signals_ordering)
|
||||
}
|
||||
SyncWithValidationInterfaceQueue();
|
||||
|
||||
UnregisterValidationInterface(&sub);
|
||||
UnregisterSharedValidationInterface(sub);
|
||||
|
||||
LOCK(cs_main);
|
||||
BOOST_CHECK_EQUAL(sub.m_expected_tip, ::ChainActive().Tip()->GetBlockHash());
|
||||
BOOST_CHECK_EQUAL(sub->m_expected_tip, ::ChainActive().Tip()->GetBlockHash());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user