diff options
author | Gavin Andresen <gavinandresen@gmail.com> | 2011-11-15 14:30:15 -0500 |
---|---|---|
committer | Luke Dashjr <luke-jr+git@utopios.org> | 2011-11-15 16:59:52 -0500 |
commit | 1aafd7464f67e0ba42b18a08070a86a427e28c72 (patch) | |
tree | df8605d888c5c38be8d5f8fa3cb13d55a90c88d1 | |
parent | 586ea168c2e29b9f96b07a3a5145356af11b4dce (diff) |
Fix crash-on-osx-on-shutdown bug. And cleanup CDB handling in Rewrite.
-rw-r--r-- | src/db.cpp | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/src/db.cpp b/src/db.cpp index b2bd7e2899..023dc5947a 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) @@ -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) { |