Skip to content

Commit fadb39c

Browse files
author
MarcoFalke
committed
test: Plug memory leaks and stack-use-after-scope
1 parent 27c59dc commit fadb39c

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

src/bench/coin_selection.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,6 @@ static void CoinSelection(benchmark::State& state)
3737
LOCK(wallet.cs_wallet);
3838

3939
while (state.KeepRunning()) {
40-
// Empty wallet.
41-
for (COutput output : vCoins)
42-
delete output.tx;
43-
vCoins.clear();
44-
4540
// Add coins.
4641
for (int i = 0; i < 1000; i++)
4742
addCoin(1000 * COIN, wallet, vCoins);
@@ -53,6 +48,12 @@ static void CoinSelection(benchmark::State& state)
5348
assert(success);
5449
assert(nValueRet == 1003 * COIN);
5550
assert(setCoinsRet.size() == 2);
51+
52+
// Empty wallet.
53+
for (COutput& output : vCoins) {
54+
delete output.tx;
55+
}
56+
vCoins.clear();
5657
}
5758
}
5859

src/test/checkqueue_tests.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -406,11 +406,11 @@ BOOST_AUTO_TEST_CASE(test_CheckQueueControl_Locks)
406406
boost::thread_group tg;
407407
std::mutex m;
408408
std::condition_variable cv;
409+
bool has_lock{false};
410+
bool has_tried{false};
411+
bool done{false};
412+
bool done_ack{false};
409413
{
410-
bool has_lock {false};
411-
bool has_tried {false};
412-
bool done {false};
413-
bool done_ack {false};
414414
std::unique_lock<std::mutex> l(m);
415415
tg.create_thread([&]{
416416
CCheckQueueControl<FakeCheck> control(queue.get());

src/test/test_bitcoin.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ void CConnmanTest::AddNode(CNode& node)
2828
void CConnmanTest::ClearNodes()
2929
{
3030
LOCK(g_connman->cs_vNodes);
31+
for (CNode* node : g_connman->vNodes) {
32+
delete node;
33+
}
3134
g_connman->vNodes.clear();
3235
}
3336

0 commit comments

Comments
 (0)