aboutsummaryrefslogtreecommitdiff
path: root/src/rpc/mining.cpp
diff options
context:
space:
mode:
authorMarcoFalke <falke.marco@gmail.com>2020-04-27 10:35:32 -0400
committerfanquake <fanquake@gmail.com>2020-05-15 07:42:08 +0800
commitcc7d34465bbb0195d8bcd9143097840a2e9765f2 (patch)
tree21c484795f906d9de0e7dd7dff73421525854a89 /src/rpc/mining.cpp
parent37a620748bd3578eda1c74daad8df8451d13b989 (diff)
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. Github-Pull: #18742 Rebased-From: 7777f2a4bb1f9d843bc50a4e35085cfbb2808780
Diffstat (limited to 'src/rpc/mining.cpp')
-rw-r--r--src/rpc/mining.cpp12
1 files changed, 6 insertions, 6 deletions
diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp
index da9d583fa7..94590e0da4 100644
--- a/src/rpc/mining.cpp
+++ b/src/rpc/mining.cpp
@@ -724,7 +724,7 @@ static UniValue getblocktemplate(const JSONRPCRequest& request)
return result;
}
-class submitblock_StateCatcher : public CValidationInterface
+class submitblock_StateCatcher final : public CValidationInterface
{
public:
uint256 hash;
@@ -792,17 +792,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)