Skip to content

Commit

Permalink
wallet: Close wallet env lock file
Browse files Browse the repository at this point in the history
Close .walletlock file when a BerkeleyEnvironment is deleted.

Github-Pull: bitcoin#15297
Rebased-From: 2f8b8f4
  • Loading branch information
promag committed Mar 12, 2019
1 parent 22cdb6c commit 2e9e904
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/util.cpp
Expand Up @@ -174,6 +174,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);
Expand Down
1 change: 1 addition & 0 deletions src/util.h
Expand Up @@ -77,6 +77,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
Expand Down
2 changes: 2 additions & 0 deletions src/wallet/db.cpp
Expand Up @@ -136,6 +136,8 @@ void BerkeleyEnvironment::Close()
DbEnv((u_int32_t)0).remove(strPath.c_str(), 0);

if (error_file) fclose(error_file);

UnlockDirectory(strPath, ".walletlock");
}

void BerkeleyEnvironment::Reset()
Expand Down

0 comments on commit 2e9e904

Please sign in to comment.