diff --git a/libethereum/Executive.cpp b/libethereum/Executive.cpp index 6a123875c..db77d349a 100644 --- a/libethereum/Executive.cpp +++ b/libethereum/Executive.cpp @@ -32,13 +32,6 @@ using namespace dev::eth; #define ETH_VMTRACE 1 -Executive::~Executive() -{ - // TODO: Make safe. - delete m_ext; - delete m_vm; -} - u256 Executive::gasUsed() const { return m_t.gas() - m_endGas; @@ -112,9 +105,9 @@ bool Executive::call(Address _receiveAddress, Address _senderAddress, u256 _valu if (m_s.addressHasCode(_receiveAddress)) { - m_vm = new VM(_gas); + m_vm.reset(new VM(_gas)); bytes const& c = m_s.code(_receiveAddress); - m_ext = new ExtVM(m_s, _receiveAddress, _senderAddress, _originAddress, _value, _gasPrice, _data, &c, m_ms); + m_ext.reset(new ExtVM(m_s, _receiveAddress, _senderAddress, _originAddress, _value, _gasPrice, _data, &c, m_ms)); } else m_endGas = _gas; @@ -131,8 +124,8 @@ bool Executive::create(Address _sender, u256 _endowment, u256 _gasPrice, u256 _g m_s.m_cache[m_newAddress] = Account(m_s.balance(m_newAddress) + _endowment, Account::ContractConception); // Execute _init. - m_vm = new VM(_gas); - m_ext = new ExtVM(m_s, m_newAddress, _sender, _origin, _endowment, _gasPrice, bytesConstRef(), _init, m_ms); + m_vm.reset(new VM(_gas)); + m_ext.reset(new ExtVM(m_s, m_newAddress, _sender, _origin, _endowment, _gasPrice, bytesConstRef(), _init, m_ms)); return _init.empty(); } diff --git a/libethereum/Executive.h b/libethereum/Executive.h index 930c2859b..f2ee6a77d 100644 --- a/libethereum/Executive.h +++ b/libethereum/Executive.h @@ -25,18 +25,17 @@ #include #include #include -#include +#include #include "Transaction.h" -#include "Manifest.h" +#include "ExtVM.h" namespace dev { namespace eth { -class VM; -class ExtVM; class State; +struct Manifest; struct VMTraceChannel: public LogChannel { static const char* name() { return "EVM"; } static const int verbosity = 11; }; @@ -44,7 +43,9 @@ class Executive { public: Executive(State& _s, Manifest* o_ms = nullptr): m_s(_s), m_ms(o_ms) {} - ~Executive(); + ~Executive() = default; + Executive(Executive const&) = delete; + void operator=(Executive) = delete; bool setup(bytesConstRef _transaction); bool create(Address _txSender, u256 _endowment, u256 _gasPrice, u256 _gas, bytesConstRef _code, Address _originAddress); @@ -63,14 +64,14 @@ public: h160 newAddress() const { return m_newAddress; } LogEntries const& logs() const { return m_logs; } - VM const& vm() const { return *m_vm; } + VMFace const& vm() const { return *m_vm; } State const& state() const { return m_s; } ExtVM const& ext() const { return *m_ext; } private: State& m_s; - ExtVM* m_ext = nullptr; // TODO: make safe. - VM* m_vm = nullptr; + std::unique_ptr m_ext; + std::unique_ptr m_vm; Manifest* m_ms = nullptr; bytesConstRef m_out; Address m_newAddress; diff --git a/libethereum/State.cpp b/libethereum/State.cpp index 9a0426e18..335b7ff04 100644 --- a/libethereum/State.cpp +++ b/libethereum/State.cpp @@ -33,6 +33,7 @@ #include "BlockChain.h" #include "Defaults.h" #include "ExtVM.h" +#include "Executive.h" using namespace std; using namespace dev; using namespace dev::eth; diff --git a/libethereum/State.h b/libethereum/State.h index 9c41843ff..5fcfa1cf7 100644 --- a/libethereum/State.h +++ b/libethereum/State.h @@ -36,7 +36,6 @@ #include "Account.h" #include "Transaction.h" #include "TransactionReceipt.h" -#include "Executive.h" #include "AccountDiff.h" namespace dev diff --git a/test/vm.cpp b/test/vm.cpp index d7bc0612a..67102dcd2 100644 --- a/test/vm.cpp +++ b/test/vm.cpp @@ -21,6 +21,7 @@ */ #include +#include #include "vm.h" using namespace std;