From fa5cef0f785705474251faa4b5bf0f94c7100420 Mon Sep 17 00:00:00 2001 From: MarcoFalke Date: Tue, 27 Nov 2018 16:53:49 -0500 Subject: [PATCH] bench: Destroy wallet txs instead of leaking their memory --- src/bench/coin_selection.cpp | 29 +++++++++++++++-------------- test/sanitizer_suppressions/lsan | 4 ---- 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/src/bench/coin_selection.cpp b/src/bench/coin_selection.cpp index 8552ed34f..74641191a 100644 --- a/src/bench/coin_selection.cpp +++ b/src/bench/coin_selection.cpp @@ -4,25 +4,19 @@ #include #include -#include #include +#include #include -static void addCoin(const CAmount& nValue, const CWallet& wallet, std::vector& groups) +static void addCoin(const CAmount& nValue, const CWallet& wallet, std::vector>& wtxs) { - int nInput = 0; - static int nextLockTime = 0; CMutableTransaction tx; tx.nLockTime = nextLockTime++; // so all transactions get different hashes - tx.vout.resize(nInput + 1); - tx.vout[nInput].nValue = nValue; - CWalletTx* wtx = new CWalletTx(&wallet, MakeTransactionRef(std::move(tx))); - - int nAge = 6 * 24; - COutput output(wtx, nInput, nAge, true /* spendable */, true /* solvable */, true /* safe */); - groups.emplace_back(output.GetInputCoin(), 6, false, 0, 0); + tx.vout.resize(1); + tx.vout[0].nValue = nValue; + wtxs.push_back(MakeUnique(&wallet, MakeTransactionRef(std::move(tx)))); } // Simple benchmark for wallet coin selection. Note that it maybe be necessary @@ -36,14 +30,21 @@ static void CoinSelection(benchmark::State& state) { auto chain = interfaces::MakeChain(); const CWallet wallet(*chain, WalletLocation(), WalletDatabase::CreateDummy()); + std::vector> wtxs; LOCK(wallet.cs_wallet); // Add coins. - std::vector groups; for (int i = 0; i < 1000; ++i) { - addCoin(1000 * COIN, wallet, groups); + addCoin(1000 * COIN, wallet, wtxs); + } + addCoin(3 * COIN, wallet, wtxs); + + // Create groups + std::vector groups; + for (const auto& wtx : wtxs) { + COutput output(wtx.get(), 0 /* iIn */, 6 * 24 /* nDepthIn */, true /* spendable */, true /* solvable */, true /* safe */); + groups.emplace_back(output.GetInputCoin(), 6, false, 0, 0); } - addCoin(3 * COIN, wallet, groups); const CoinEligibilityFilter filter_standard(1, 6, 0); const CoinSelectionParams coin_selection_params(true, 34, 148, CFeeRate(0), 0); diff --git a/test/sanitizer_suppressions/lsan b/test/sanitizer_suppressions/lsan index 57bc2c2be..6f15c0f1d 100644 --- a/test/sanitizer_suppressions/lsan +++ b/test/sanitizer_suppressions/lsan @@ -1,7 +1,3 @@ -# Suppress warnings about addCoin(...) leak in the CoinSelection benchmark -leak:addCoin -leak:bench_bitcoin - # Suppress warnings triggered in dependencies leak:libcrypto leak:libqminimal