From 95316118206aeed718ae6260ef9b5a1a4a6dacd8 Mon Sep 17 00:00:00 2001 From: Determinant Date: Thu, 19 Jul 2018 14:43:35 -0400 Subject: fix mem leak --- include/hotstuff/consensus.h | 8 +++++--- include/hotstuff/entity.h | 2 +- run_replicas.sh | 4 ++-- salticidae | 2 +- src/consensus.cpp | 2 +- src/hotstuff.cpp | 2 ++ src/hotstuff_client.cpp | 4 ++-- 7 files changed, 14 insertions(+), 10 deletions(-) diff --git a/include/hotstuff/consensus.h b/include/hotstuff/consensus.h index 1f1e6ea..a3a1f25 100644 --- a/include/hotstuff/consensus.h +++ b/include/hotstuff/consensus.h @@ -45,7 +45,9 @@ class HotStuffCore { BoxObj storage; HotStuffCore(ReplicaID id, privkey_bt &&priv_key); - virtual ~HotStuffCore() = default; + virtual ~HotStuffCore() { + b0->qc_ref = nullptr; + } /* Inputs of the state machine triggered by external events, should called * by the class user, with proper invariants. */ @@ -173,7 +175,7 @@ struct Proposal: public Serializable { << "rid=" << std::to_string(proposer) << " " << "bqc=" << get_hex10(bqc_hash) << " " << "blk=" << get_hex10(blk->get_hash()) << ">"; - return std::string(std::move(s)); + return std::move(s); } }; @@ -243,7 +245,7 @@ struct Vote: public Serializable { << "bqc=" << get_hex10(bqc_hash) << " " << "blk=" << get_hex10(blk_hash) << " " << "cert=" << (cert ? "yes" : "no") << ">"; - return std::string(std::move(s)); + return std::move(s); } }; diff --git a/include/hotstuff/entity.h b/include/hotstuff/entity.h index 03aff06..28b5148 100644 --- a/include/hotstuff/entity.h +++ b/include/hotstuff/entity.h @@ -184,7 +184,7 @@ class Block { << "id=" << get_hex10(hash) << " " << "height=" << std::to_string(height) << " " << "parent=" << get_hex10(parent_hashes[0]) << ">"; - return std::string(std::move(s)); + return std::move(s); } }; diff --git a/run_replicas.sh b/run_replicas.sh index 213b6b7..450dac3 100755 --- a/run_replicas.sh +++ b/run_replicas.sh @@ -5,7 +5,7 @@ if [[ $# -gt 0 ]]; then fi for i in "${rep[@]}"; do echo "starting replica $i" - #valgrind ./hotstuff-app --conf hotstuff-sec${i}.conf > log${i} 2>&1 & - ./hotstuff-app --conf hotstuff-sec${i}.conf > log${i} 2>&1 & + valgrind --leak-check=full ./hotstuff-app --conf hotstuff-sec${i}.conf > log${i} 2>&1 & + #./hotstuff-app --conf hotstuff-sec${i}.conf > log${i} 2>&1 & done wait diff --git a/salticidae b/salticidae index a757789..b4bf23c 160000 --- a/salticidae +++ b/salticidae @@ -1 +1 @@ -Subproject commit a75778995a4e0742f244670e9cc02a56611ccfe0 +Subproject commit b4bf23c07601560d708fbdd7c20aca20b630c983 diff --git a/src/consensus.cpp b/src/consensus.cpp index bf4868d..6b8b398 100644 --- a/src/consensus.cpp +++ b/src/consensus.cpp @@ -287,7 +287,7 @@ HotStuffCore::operator std::string () const { << "bexec=" << get_hex10(bqc->get_hash()) << " " << "vheight=" << std::to_string(vheight) << " " << "tails=" << std::to_string(tails.size()) << ">"; - return std::string(std::move(s)); + return std::move(s); } } diff --git a/src/hotstuff.cpp b/src/hotstuff.cpp index 6230d06..a37e872 100644 --- a/src/hotstuff.cpp +++ b/src/hotstuff.cpp @@ -334,6 +334,7 @@ void HotStuffBase::print_stat() const { part_delivery_time = 0; part_delivery_time_min = double_inf; part_delivery_time_max = 0; +#ifdef HOTSTUFF_MSG_STAT LOG_INFO("-- sent opcode (10s) --"); auto &sent_op = pn.get_sent_by_opcode(); for (auto &op: sent_op) @@ -376,6 +377,7 @@ void HotStuffBase::print_stat() const { LOG_INFO("sent: %lu", nsent); LOG_INFO("recv: %lu", nrecv); LOG_INFO("====== end stats ======"); +#endif } promise_t HotStuffBase::async_decide(const uint256_t &cmd_hash) { diff --git a/src/hotstuff_client.cpp b/src/hotstuff_client.cpp index f9bfb94..bee60c3 100644 --- a/src/hotstuff_client.cpp +++ b/src/hotstuff_client.cpp @@ -39,7 +39,7 @@ struct Request { std::unordered_map buffers; std::unordered_map waiting; -MsgNetwork mn(eb, 10, 0, 2, 4096); +MsgNetwork mn(eb, 10, 10, 4096); std::unordered_map::conn_t> conns; std::vector replicas; @@ -48,7 +48,7 @@ void set_proposer(ReplicaID rid) { proposer = rid; auto it = conns.find(rid); if (it == conns.end()) - conns.insert(std::make_pair(rid, mn.create_conn(replicas[rid]))); + conns.insert(std::make_pair(rid, mn.connect(replicas[rid]))); } void try_send() { -- cgit v1.2.3