Skip to content

Commit

Permalink
Merge pull request #636 from gavinandresen/master
Browse files Browse the repository at this point in the history
Fix crash-on-wallet-upgrade bug on OSX
  • Loading branch information
gavinandresen committed Nov 15, 2011
2 parents 709c1b2 + c4de918 commit 1b93ea0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
2 changes: 1 addition & 1 deletion bitcoin-qt.pro
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
21 changes: 14 additions & 7 deletions src/db.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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();
Expand Down Expand Up @@ -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();
Expand All @@ -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)
{
Expand Down

0 comments on commit 1b93ea0

Please sign in to comment.