@ -90,13 +90,13 @@ void BerkeleyEnvironment::Close()
fDbEnvInit = false ;
for ( auto & db : m apDb ) {
for ( auto & db : m _databases ) {
auto count = mapFileUseCount . find ( db . first ) ;
assert ( count = = mapFileUseCount . end ( ) | | count - > second = = 0 ) ;
if ( db . second ) {
db . second - > close ( 0 ) ;
delete db . second ;
d b. second = nullptr ;
BerkeleyDatabase & database = db . second . get ( ) ;
if ( database . m_db ) {
database . m_db - > close ( 0 ) ;
d atabase. m_db . reset ( ) ;
}
}
@ -463,7 +463,7 @@ BerkeleyBatch::BerkeleyBatch(BerkeleyDatabase& database, const char* pszMode, bo
if ( ! env - > Open ( false /* retry */ ) )
throw std : : runtime_error ( " BerkeleyBatch: Failed to open database environment. " ) ;
pdb = env- > mapDb [ strFilename ] ;
pdb = database. m_db . get ( ) ;
if ( pdb = = nullptr ) {
int ret ;
std : : unique_ptr < Db > pdb_temp = MakeUnique < Db > ( env - > dbenv . get ( ) , 0 ) ;
@ -508,7 +508,7 @@ BerkeleyBatch::BerkeleyBatch(BerkeleyDatabase& database, const char* pszMode, bo
}
pdb = pdb_temp . release ( ) ;
env- > mapDb [ strFilename ] = pdb ;
database. m_db . reset ( pdb ) ;
if ( fCreate & & ! Exists ( std : : string ( " version " ) ) ) {
bool fTmp = fReadOnly ;
@ -563,12 +563,13 @@ void BerkeleyEnvironment::CloseDb(const std::string& strFile)
{
{
LOCK ( cs_db ) ;
if ( mapDb [ strFile ] ! = nullptr ) {
auto it = m_databases . find ( strFile ) ;
assert ( it ! = m_databases . end ( ) ) ;
BerkeleyDatabase & database = it - > second . get ( ) ;
if ( database . m_db ) {
// Close the database handle
Db * pdb = mapDb [ strFile ] ;
pdb - > close ( 0 ) ;
delete pdb ;
mapDb [ strFile ] = nullptr ;
database . m_db - > close ( 0 ) ;
database . m_db . reset ( ) ;
}
}
}
@ -586,7 +587,7 @@ void BerkeleyEnvironment::ReloadDbEnv()
} ) ;
std : : vector < std : : string > filenames ;
for ( auto it : m apDb ) {
for ( auto it : m _databases ) {
filenames . push_back ( it . first ) ;
}
// Close the individual Db's