Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Feb 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions src/bench/coin_selection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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();
Copy link
Member

@promag promag Feb 19, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit, std::vector<COutput> vCoins could be declared inside while() to avoid explicit clear.

}
}

Expand Down
8 changes: 4 additions & 4 deletions src/test/checkqueue_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch.

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());
Expand Down
3 changes: 3 additions & 0 deletions src/test/test_bitcoin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down