From d1fc5354589d4ef612be2477b9fd42aae47e1ef5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Fri, 2 Jan 2015 14:35:53 +0100 Subject: [PATCH] Memleak fix: free genesis block at the end of program --- libethereum/BlockChain.cpp | 2 +- libethereum/BlockChain.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libethereum/BlockChain.cpp b/libethereum/BlockChain.cpp index 6ed0a2ca6..b1938d54d 100644 --- a/libethereum/BlockChain.cpp +++ b/libethereum/BlockChain.cpp @@ -71,7 +71,7 @@ std::map const& dev::eth::genesisState() return s_ret; } -BlockInfo* BlockChain::s_genesis = nullptr; +std::unique_ptr BlockChain::s_genesis; boost::shared_mutex BlockChain::x_genesis; ldb::Slice dev::eth::toSlice(h256 _h, unsigned _sub) diff --git a/libethereum/BlockChain.h b/libethereum/BlockChain.h index d03818bd3..4e5d66c9a 100644 --- a/libethereum/BlockChain.h +++ b/libethereum/BlockChain.h @@ -132,7 +132,7 @@ public: h256Set allUnclesFrom(h256 _parent) const; /// @returns the genesis block header. - static BlockInfo const& genesis() { UpgradableGuard l(x_genesis); if (!s_genesis) { auto gb = createGenesisBlock(); UpgradeGuard ul(l); (s_genesis = new BlockInfo)->populate(&gb); } return *s_genesis; } + static BlockInfo const& genesis() { UpgradableGuard l(x_genesis); if (!s_genesis) { auto gb = createGenesisBlock(); UpgradeGuard ul(l); s_genesis.reset(new BlockInfo); s_genesis->populate(&gb); } return *s_genesis; } /// @returns the genesis block as its RLP-encoded byte array. /// @note This is slow as it's constructed anew each call. Consider genesis() instead. @@ -211,7 +211,7 @@ private: /// Static genesis info and its lock. static boost::shared_mutex x_genesis; - static BlockInfo* s_genesis; + static std::unique_ptr s_genesis; }; std::ostream& operator<<(std::ostream& _out, BlockChain const& _bc);