Skip to content

Commit 2f8b8f4

Browse files
committed
wallet: Close wallet env lock file
Close .walletlock file when a BerkeleyEnvironment is deleted.
1 parent 8602a1e commit 2f8b8f4

File tree

3 files changed

+9
-0
lines changed

3 files changed

+9
-0
lines changed

src/util/system.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,12 @@ bool LockDirectory(const fs::path& directory, const std::string lockfile_name, b
116116
return true;
117117
}
118118

119+
void UnlockDirectory(const fs::path& directory, const std::string& lockfile_name)
120+
{
121+
std::lock_guard<std::mutex> lock(cs_dir_locks);
122+
dir_locks.erase((directory / lockfile_name).string());
123+
}
124+
119125
void ReleaseDirectoryLocks()
120126
{
121127
std::lock_guard<std::mutex> ulock(cs_dir_locks);

src/util/system.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ int RaiseFileDescriptorLimit(int nMinFD);
7070
void AllocateFileRange(FILE *file, unsigned int offset, unsigned int length);
7171
bool RenameOver(fs::path src, fs::path dest);
7272
bool LockDirectory(const fs::path& directory, const std::string lockfile_name, bool probe_only=false);
73+
void UnlockDirectory(const fs::path& directory, const std::string& lockfile_name);
7374
bool DirIsWritable(const fs::path& directory);
7475

7576
/** Release all directory locks. This is used for unit testing only, at runtime

src/wallet/db.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ void BerkeleyEnvironment::Close()
136136
DbEnv((u_int32_t)0).remove(strPath.c_str(), 0);
137137

138138
if (error_file) fclose(error_file);
139+
140+
UnlockDirectory(strPath, ".walletlock");
139141
}
140142

141143
void BerkeleyEnvironment::Reset()

0 commit comments

Comments
 (0)