test: Plug memory leaks and stack-use-after-scope

This commit is contained in:
MarcoFalke 2018-02-17 14:29:56 -05:00
parent 27c59dc502
commit fadb39ca62
No known key found for this signature in database
GPG key ID: CE2B75697E69A548
3 changed files with 13 additions and 9 deletions

View file

@ -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();
}
}

View file

@ -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<std::mutex> l(m);
tg.create_thread([&]{
CCheckQueueControl<FakeCheck> control(queue.get());

View file

@ -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();
}