aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMeshCollider <dobsonsa68@gmail.com>2019-02-06 10:09:24 +1300
committerMeshCollider <dobsonsa68@gmail.com>2019-02-06 10:10:51 +1300
commit30e799a5f7053d4050280aced2c9d8c5f0fea20e (patch)
tree481c7755a0a3117a30ff47cd4b149eab928ecf4d /src
parent3a573fd46c75ed76df38580d45cc36c6d598f3ea (diff)
parentd3bf3b930d34da7d121ae35b4fb75865ed73208c (diff)
downloadbitcoin-30e799a5f7053d4050280aced2c9d8c5f0fea20e.tar.xz
Merge #15297: wallet: Releases dangling files on BerkeleyEnvironment::Close
d3bf3b930 qa: Test .walletlock file is closed (João Barbosa) 2f8b8f479 wallet: Close wallet env lock file (João Barbosa) 8602a1e6a wallet: Close dbenv error file db.log (João Barbosa) Pull request description: This PR closes `db.log` and removes `.walletlock` files when `BerkeleyEnvironment` is closed. Fixes https://github.com/bitcoin/bitcoin/issues/15291#issuecomment-459131886. Tree-SHA512: 05d8b027feea914e0ba873e75d117857473d1fd7b400e41bd473d638171fa39d5be048990bf685dc0807f7d92418579b763056dc2a6dcf6b96777d5688ddee04
Diffstat (limited to 'src')
-rw-r--r--src/util/system.cpp6
-rw-r--r--src/util/system.h1
-rw-r--r--src/wallet/db.cpp7
3 files changed, 14 insertions, 0 deletions
diff --git a/src/util/system.cpp b/src/util/system.cpp
index 789dcfaba9..bb9fcab59e 100644
--- a/src/util/system.cpp
+++ b/src/util/system.cpp
@@ -111,6 +111,12 @@ bool LockDirectory(const fs::path& directory, const std::string lockfile_name, b
return true;
}
+void UnlockDirectory(const fs::path& directory, const std::string& lockfile_name)
+{
+ std::lock_guard<std::mutex> lock(cs_dir_locks);
+ dir_locks.erase((directory / lockfile_name).string());
+}
+
void ReleaseDirectoryLocks()
{
std::lock_guard<std::mutex> ulock(cs_dir_locks);
diff --git a/src/util/system.h b/src/util/system.h
index 5932e55793..17723d427d 100644
--- a/src/util/system.h
+++ b/src/util/system.h
@@ -70,6 +70,7 @@ int RaiseFileDescriptorLimit(int nMinFD);
void AllocateFileRange(FILE *file, unsigned int offset, unsigned int length);
bool RenameOver(fs::path src, fs::path dest);
bool LockDirectory(const fs::path& directory, const std::string lockfile_name, bool probe_only=false);
+void UnlockDirectory(const fs::path& directory, const std::string& lockfile_name);
bool DirIsWritable(const fs::path& directory);
/** Release all directory locks. This is used for unit testing only, at runtime
diff --git a/src/wallet/db.cpp b/src/wallet/db.cpp
index cfa9bdd20e..c64a85c910 100644
--- a/src/wallet/db.cpp
+++ b/src/wallet/db.cpp
@@ -126,11 +126,18 @@ void BerkeleyEnvironment::Close()
}
}
+ FILE* error_file = nullptr;
+ dbenv->get_errfile(&error_file);
+
int ret = dbenv->close(0);
if (ret != 0)
LogPrintf("BerkeleyEnvironment::Close: Error %d closing database environment: %s\n", ret, DbEnv::strerror(ret));
if (!fMockDb)
DbEnv((u_int32_t)0).remove(strPath.c_str(), 0);
+
+ if (error_file) fclose(error_file);
+
+ UnlockDirectory(strPath, ".walletlock");
}
void BerkeleyEnvironment::Reset()