Skip to content

Commit 2e9e904

Browse files
committed
wallet: Close wallet env lock file
Close .walletlock file when a BerkeleyEnvironment is deleted. Github-Pull: bitcoin#15297 Rebased-From: 2f8b8f4
1 parent 22cdb6c commit 2e9e904

File tree

3 files changed

+9
-0
lines changed

3 files changed

+9
-0
lines changed

src/util.cpp

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

177+
void UnlockDirectory(const fs::path& directory, const std::string& lockfile_name)
178+
{
179+
std::lock_guard<std::mutex> lock(cs_dir_locks);
180+
dir_locks.erase((directory / lockfile_name).string());
181+
}
182+
177183
void ReleaseDirectoryLocks()
178184
{
179185
std::lock_guard<std::mutex> ulock(cs_dir_locks);

src/util.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ int RaiseFileDescriptorLimit(int nMinFD);
7777
void AllocateFileRange(FILE *file, unsigned int offset, unsigned int length);
7878
bool RenameOver(fs::path src, fs::path dest);
7979
bool LockDirectory(const fs::path& directory, const std::string lockfile_name, bool probe_only=false);
80+
void UnlockDirectory(const fs::path& directory, const std::string& lockfile_name);
8081
bool DirIsWritable(const fs::path& directory);
8182

8283
/** 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)