diff --git a/src/util.cpp b/src/util.cpp index 6738bbc6e4470..c22913e37e1d1 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -380,13 +380,14 @@ bool LockDirectory(const fs::path& directory, const std::string lockfile_name, b if (file) fclose(file); try { - static std::map locks; - boost::interprocess::file_lock& lock = locks.emplace(pathLockFile.string(), pathLockFile.string().c_str()).first->second; - if (!lock.try_lock()) { + static std::map> locks; + std::unique_ptr &lock = locks.emplace(pathLockFile.string(), + MakeUnique(pathLockFile.string().c_str())).first->second; + if (!lock->try_lock()) { return false; } if (probe_only) { - lock.unlock(); + lock->unlock(); } } catch (const boost::interprocess::interprocess_exception& e) { return error("Error while attempting to lock directory %s: %s", directory.string(), e.what());