mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-12 06:58:57 +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:
@@ -874,7 +874,7 @@ static UniValue getblocktemplate(const JSONRPCRequest& request)
|
||||
return result;
|
||||
}
|
||||
|
||||
class submitblock_StateCatcher : public CValidationInterface
|
||||
class submitblock_StateCatcher final : public CValidationInterface
|
||||
{
|
||||
public:
|
||||
uint256 hash;
|
||||
@@ -942,17 +942,17 @@ static UniValue submitblock(const JSONRPCRequest& request)
|
||||
}
|
||||
|
||||
bool new_block;
|
||||
submitblock_StateCatcher sc(block.GetHash());
|
||||
RegisterValidationInterface(&sc);
|
||||
auto sc = std::make_shared<submitblock_StateCatcher>(block.GetHash());
|
||||
RegisterSharedValidationInterface(sc);
|
||||
bool accepted = ProcessNewBlock(Params(), blockptr, /* fForceProcessing */ true, /* fNewBlock */ &new_block);
|
||||
UnregisterValidationInterface(&sc);
|
||||
UnregisterSharedValidationInterface(sc);
|
||||
if (!new_block && accepted) {
|
||||
return "duplicate";
|
||||
}
|
||||
if (!sc.found) {
|
||||
if (!sc->found) {
|
||||
return "inconclusive";
|
||||
}
|
||||
return BIP22ValidationResult(sc.state);
|
||||
return BIP22ValidationResult(sc->state);
|
||||
}
|
||||
|
||||
static UniValue submitheader(const JSONRPCRequest& request)
|
||||
|
||||
Reference in New Issue
Block a user