From fadb39ca6237781346ca3da319e2bd9e48a5a604 Mon Sep 17 00:00:00 2001 From: MarcoFalke Date: Sat, 17 Feb 2018 14:29:56 -0500 Subject: [PATCH] test: Plug memory leaks and stack-use-after-scope --- src/bench/coin_selection.cpp | 11 ++++++----- src/test/checkqueue_tests.cpp | 8 ++++---- src/test/test_bitcoin.cpp | 3 +++ 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/bench/coin_selection.cpp b/src/bench/coin_selection.cpp index 06d2abeac..6f438b60e 100644 --- a/src/bench/coin_selection.cpp +++ b/src/bench/coin_selection.cpp @@ -37,11 +37,6 @@ static void CoinSelection(benchmark::State& state) LOCK(wallet.cs_wallet); while (state.KeepRunning()) { - // Empty wallet. - for (COutput output : vCoins) - delete output.tx; - vCoins.clear(); - // Add coins. for (int i = 0; i < 1000; i++) addCoin(1000 * COIN, wallet, vCoins); @@ -53,6 +48,12 @@ static void CoinSelection(benchmark::State& state) assert(success); assert(nValueRet == 1003 * COIN); assert(setCoinsRet.size() == 2); + + // Empty wallet. + for (COutput& output : vCoins) { + delete output.tx; + } + vCoins.clear(); } } diff --git a/src/test/checkqueue_tests.cpp b/src/test/checkqueue_tests.cpp index 42f9dd060..8e0ec5243 100644 --- a/src/test/checkqueue_tests.cpp +++ b/src/test/checkqueue_tests.cpp @@ -406,11 +406,11 @@ BOOST_AUTO_TEST_CASE(test_CheckQueueControl_Locks) boost::thread_group tg; std::mutex m; std::condition_variable cv; + bool has_lock{false}; + bool has_tried{false}; + bool done{false}; + bool done_ack{false}; { - bool has_lock {false}; - bool has_tried {false}; - bool done {false}; - bool done_ack {false}; std::unique_lock l(m); tg.create_thread([&]{ CCheckQueueControl control(queue.get()); diff --git a/src/test/test_bitcoin.cpp b/src/test/test_bitcoin.cpp index bdd44489f..95c4825b8 100644 --- a/src/test/test_bitcoin.cpp +++ b/src/test/test_bitcoin.cpp @@ -28,6 +28,9 @@ void CConnmanTest::AddNode(CNode& node) void CConnmanTest::ClearNodes() { LOCK(g_connman->cs_vNodes); + for (CNode* node : g_connman->vNodes) { + delete node; + } g_connman->vNodes.clear(); }