Skip to content

Commit

Permalink
test: cleanup leveldb env
Browse files Browse the repository at this point in the history
Rationale:
    Some classes in LevelDB do not get freed unless the environment
    is deleted.
  • Loading branch information
div72 committed Dec 24, 2023
1 parent 15b19fb commit c01ba5d
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/test/test_gridcoin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#include "random.h"
#include "wallet/wallet.h"

leveldb::Env* txdb_env;

extern CWallet* pwalletMain;
extern leveldb::DB *txdb;
extern CClientUIInterface uiInterface;
Expand Down Expand Up @@ -48,7 +50,7 @@ struct TestingSetup {

// TODO: Refactor CTxDB to something like bitcoin's current CDBWrapper and remove this workaround.
leveldb::Options db_options;
db_options.env = leveldb::NewMemEnv(leveldb::Env::Default()); // Use a memory environment to avoid polluting the production leveldb.
db_options.env = txdb_env = leveldb::NewMemEnv(leveldb::Env::Default()); // Use a memory environment to avoid polluting the production leveldb.
db_options.create_if_missing = true;
db_options.error_if_exists = true;
assert(leveldb::DB::Open(db_options, "", &txdb).ok());
Expand All @@ -71,7 +73,9 @@ struct TestingSetup {
bitdb.Flush(true);
g_banman.reset();
delete txdb;
delete txdb_env;
txdb = nullptr;
txdb_env = nullptr;
g_mock_deterministic_tests = false;
ECC_Stop();
}
Expand Down

0 comments on commit c01ba5d

Please sign in to comment.