Skip to content

Commit cbec57f

Browse files
committed
Merge pull request #6282
0ce30ea fix crash on shutdown when e.g. changing -txindex and abort action (Philip Kaufmann)
2 parents 9849c66 + 0ce30ea commit cbec57f

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

src/wallet/db.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ void CDBEnv::EnvShutdown()
4343
if (ret != 0)
4444
LogPrintf("CDBEnv::EnvShutdown: Error %d shutting down database environment: %s\n", ret, DbEnv::strerror(ret));
4545
if (!fMockDb)
46-
DbEnv(0).remove(path.string().c_str(), 0);
46+
DbEnv(0).remove(strPath.c_str(), 0);
4747
}
4848

4949
void CDBEnv::Reset()
@@ -78,10 +78,10 @@ bool CDBEnv::Open(const boost::filesystem::path& pathIn)
7878

7979
boost::this_thread::interruption_point();
8080

81-
path = pathIn;
82-
boost::filesystem::path pathLogDir = path / "database";
81+
strPath = pathIn.string();
82+
boost::filesystem::path pathLogDir = pathIn / "database";
8383
TryCreateDirectory(pathLogDir);
84-
boost::filesystem::path pathErrorFile = path / "db.log";
84+
boost::filesystem::path pathErrorFile = pathIn / "db.log";
8585
LogPrintf("CDBEnv::Open: LogDir=%s ErrorFile=%s\n", pathLogDir.string(), pathErrorFile.string());
8686

8787
unsigned int nEnvFlags = 0;
@@ -98,7 +98,7 @@ bool CDBEnv::Open(const boost::filesystem::path& pathIn)
9898
dbenv->set_flags(DB_AUTO_COMMIT, 1);
9999
dbenv->set_flags(DB_TXN_WRITE_NOSYNC, 1);
100100
dbenv->log_set_config(DB_LOG_AUTO_REMOVE, 1);
101-
int ret = dbenv->open(path.string().c_str(),
101+
int ret = dbenv->open(strPath.c_str(),
102102
DB_CREATE |
103103
DB_INIT_LOCK |
104104
DB_INIT_LOG |
@@ -455,7 +455,7 @@ void CDBEnv::Flush(bool fShutdown)
455455
dbenv->log_archive(&listp, DB_ARCH_REMOVE);
456456
Close();
457457
if (!fMockDb)
458-
boost::filesystem::remove_all(path / "database");
458+
boost::filesystem::remove_all(boost::filesystem::path(strPath) / "database");
459459
}
460460
}
461461
}

src/wallet/db.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ class CDBEnv
2727
private:
2828
bool fDbEnvInit;
2929
bool fMockDb;
30-
boost::filesystem::path path;
30+
// Don't change into boost::filesystem::path, as that can result in
31+
// shutdown problems/crashes caused by a static initialized internal pointer.
32+
std::string strPath;
3133

3234
void EnvShutdown();
3335

0 commit comments

Comments
 (0)