aboutsummaryrefslogtreecommitdiff
path: root/src/db.cpp
diff options
context:
space:
mode:
authorGavin Andresen <gavinandresen@gmail.com>2011-11-15 13:48:12 -0800
committerGavin Andresen <gavinandresen@gmail.com>2011-11-15 13:48:12 -0800
commit1b93ea0e31c82bd23f2ddc0b5a98707fcbddce27 (patch)
treec9d7ad5fc70eac52351d22048f135c1169a8219d /src/db.cpp
parent709c1b267fcf4992ede95e7aff3ed333c068dfa5 (diff)
parentc4de918478dbcf72a9f76b27435bd1d892e1e339 (diff)
Merge pull request #636 from gavinandresen/masterv0.5.0rc5
Fix crash-on-wallet-upgrade bug on OSX
Diffstat (limited to 'src/db.cpp')
-rw-r--r--src/db.cpp21
1 files changed, 14 insertions, 7 deletions
diff --git a/src/db.cpp b/src/db.cpp
index d769cae71f..efd2a375ef 100644
--- a/src/db.cpp
+++ b/src/db.cpp
@@ -34,7 +34,14 @@ static void EnvShutdown(bool fRemoveLogFiles)
return;
fDbEnvInit = false;
- dbenv.close(0);
+ try
+ {
+ dbenv.close(0);
+ }
+ catch (const DbException& e)
+ {
+ printf("EnvShutdown exception: %s (%d)\n", e.what(), e.get_errno());
+ }
DbEnv(0).remove(GetDataDir().c_str(), 0);
if (fRemoveLogFiles)
@@ -44,7 +51,7 @@ static void EnvShutdown(bool fRemoveLogFiles)
while (it != filesystem::directory_iterator())
{
const filesystem::path& p = it->path();
-#if BOOST_FILESYSTEM_VERSION == 3
+#if BOOST_FILESYSTEM_VERSION >= 3
std::string f = p.filename().generic_string();
#else
std::string f = p.filename();
@@ -229,7 +236,10 @@ bool CDB::Rewrite(const string& strFile, const char* pszSkip)
CDataStream ssValue;
int ret = db.ReadAtCursor(pcursor, ssKey, ssValue, DB_NEXT);
if (ret == DB_NOTFOUND)
+ {
+ pcursor->close();
break;
+ }
else if (ret != 0)
{
pcursor->close();
@@ -253,14 +263,11 @@ bool CDB::Rewrite(const string& strFile, const char* pszSkip)
}
if (fSuccess)
{
- Db* pdb = mapDb[strFile];
- if (pdb->close(0))
- fSuccess = false;
+ db.Close();
+ CloseDb(strFile);
if (pdbCopy->close(0))
fSuccess = false;
- delete pdb;
delete pdbCopy;
- mapDb[strFile] = NULL;
}
if (fSuccess)
{