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:
MarcoFalke
2020-04-27 10:35:32 -04:00
parent fa5ceb25fc
commit 7777f2a4bb
3 changed files with 14 additions and 16 deletions

View File

@@ -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)