Skip to content

Commit 6b03bfb

Browse files
committed
Fix memory leak in wallet tests
1 parent f94f3e0 commit 6b03bfb

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/wallet/test/wallet_tests.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323

2424
using namespace std;
2525

26+
std::vector<std::unique_ptr<CWalletTx>> wtxn;
27+
2628
typedef set<pair<const CWalletTx*,unsigned int> > CoinSet;
2729

2830
BOOST_FIXTURE_TEST_SUITE(wallet_tests, WalletTestingSetup)
@@ -42,21 +44,21 @@ static void add_coin(const CAmount& nValue, int nAge = 6*24, bool fIsFromMe = fa
4244
// so stop vin being empty, and cache a non-zero Debit to fake out IsFromMe()
4345
tx.vin.resize(1);
4446
}
45-
CWalletTx* wtx = new CWalletTx(&wallet, MakeTransactionRef(std::move(tx)));
47+
std::unique_ptr<CWalletTx> wtx(new CWalletTx(&wallet, MakeTransactionRef(std::move(tx))));
4648
if (fIsFromMe)
4749
{
4850
wtx->fDebitCached = true;
4951
wtx->nDebitCached = 1;
5052
}
51-
COutput output(wtx, nInput, nAge, true, true);
53+
COutput output(wtx.get(), nInput, nAge, true, true);
5254
vCoins.push_back(output);
55+
wtxn.emplace_back(std::move(wtx));
5356
}
5457

5558
static void empty_wallet(void)
5659
{
57-
BOOST_FOREACH(COutput output, vCoins)
58-
delete output.tx;
5960
vCoins.clear();
61+
wtxn.clear();
6062
}
6163

6264
static bool equal_sets(CoinSet a, CoinSet b)
@@ -349,6 +351,8 @@ BOOST_AUTO_TEST_CASE(ApproximateBestSubset)
349351
BOOST_CHECK(wallet.SelectCoinsMinConf(1003 * COIN, 1, 6, 0, vCoins, setCoinsRet, nValueRet));
350352
BOOST_CHECK_EQUAL(nValueRet, 1003 * COIN);
351353
BOOST_CHECK_EQUAL(setCoinsRet.size(), 2U);
354+
355+
empty_wallet();
352356
}
353357

354358
BOOST_AUTO_TEST_SUITE_END()

0 commit comments

Comments
 (0)