From 8d0923109deb1d6c92c5f56fe660b2594b67297d Mon Sep 17 00:00:00 2001 From: Gavin Andresen Date: Tue, 15 Nov 2011 14:30:15 -0500 Subject: [PATCH 1/2] Fix crash-on-osx-on-shutdown bug. And cleanup CDB handling in Rewrite. --- src/db.cpp | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/db.cpp b/src/db.cpp index d769cae71..643ed1f7a 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) { From c4de918478dbcf72a9f76b27435bd1d892e1e339 Mon Sep 17 00:00:00 2001 From: Gavin Andresen Date: Tue, 15 Nov 2011 14:28:51 -0500 Subject: [PATCH 2/2] Tweak handling of boost filesystem versions --- bitcoin-qt.pro | 2 +- src/db.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bitcoin-qt.pro b/bitcoin-qt.pro index a8f6b2d86..e7adabe75 100644 --- a/bitcoin-qt.pro +++ b/bitcoin-qt.pro @@ -256,7 +256,7 @@ windows:RC_FILE = src/qt/res/bitcoin-qt.rc macx:HEADERS += src/qt/macdockiconhandler.h macx:OBJECTIVE_SOURCES += src/qt/macdockiconhandler.mm macx:LIBS += -framework Foundation -framework ApplicationServices -framework AppKit -macx:DEFINES += MAC_OSX MSG_NOSIGNAL=0 BOOST_FILESYSTEM_VERSION=3 +macx:DEFINES += MAC_OSX MSG_NOSIGNAL=0 macx:ICON = src/qt/res/icons/bitcoin.icns macx:TARGET = "Bitcoin-Qt" diff --git a/src/db.cpp b/src/db.cpp index 643ed1f7a..efd2a375e 100644 --- a/src/db.cpp +++ b/src/db.cpp @@ -51,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();