diff --git a/src/bench/wallet_create.cpp b/src/bench/wallet_create.cpp index d29ef339d12..11244fe8444 100644 --- a/src/bench/wallet_create.cpp +++ b/src/bench/wallet_create.cpp @@ -47,17 +47,21 @@ static void WalletCreate(benchmark::Bench& bench, bool encrypted) const auto wallet_path = test_setup->m_path_root / "test_wallet"; const auto wallet_name = fs::PathToString(wallet_path); - bench.run([&] { - auto wallet = CreateWallet(context, wallet_name, /*load_on_start=*/std::nullopt, options, status, error_string, warnings); - assert(status == DatabaseStatus::SUCCESS); - assert(wallet != nullptr); - + std::shared_ptr wallet; + auto cleanup{[&] { + if (!wallet) return; // Release wallet - RemoveWallet(context, wallet, /*load_on_start=*/ std::nullopt); + RemoveWallet(context, wallet, /*load_on_start=*/std::nullopt); WaitForDeleteWallet(std::move(wallet)); fs::remove(wallet_path / "wallet.dat"); fs::remove(wallet_path); + }}; + bench.setup(cleanup).run([&] { + wallet = CreateWallet(context, wallet_name, /*load_on_start=*/std::nullopt, options, status, error_string, warnings); + assert(status == DatabaseStatus::SUCCESS); + assert(wallet != nullptr); }); + cleanup(); } static void WalletCreatePlain(benchmark::Bench& bench) { WalletCreate(bench, /*encrypted=*/false); }