aboutsummaryrefslogtreecommitdiff
path: root/zenserver/cache/structuredcachestore.cpp
diff options
context:
space:
mode:
authorDan Engelbrecht <[email protected]>2022-03-30 10:51:34 +0200
committerDan Engelbrecht <[email protected]>2022-03-30 10:51:34 +0200
commitddb2586b9e48003684a3cb88217bec04700730f0 (patch)
treead6ec1a52e9d7b34250ba438c75dd9c0c71d3ee8 /zenserver/cache/structuredcachestore.cpp
parentNo need to take exclusive lock while gathering references (diff)
downloadzen-ddb2586b9e48003684a3cb88217bec04700730f0.tar.xz
zen-ddb2586b9e48003684a3cb88217bec04700730f0.zip
Fix bucket creation race condition in ZenCacheMemoryLayer::Put
Diffstat (limited to 'zenserver/cache/structuredcachestore.cpp')
-rw-r--r--zenserver/cache/structuredcachestore.cpp10
1 files changed, 9 insertions, 1 deletions
diff --git a/zenserver/cache/structuredcachestore.cpp b/zenserver/cache/structuredcachestore.cpp
index d5b892d06..3d7fac13b 100644
--- a/zenserver/cache/structuredcachestore.cpp
+++ b/zenserver/cache/structuredcachestore.cpp
@@ -263,7 +263,15 @@ ZenCacheMemoryLayer::Put(std::string_view InBucket, const IoHash& HashKey, const
RwLock::ExclusiveLockScope _(m_Lock);
- Bucket = &m_Buckets[std::string(InBucket)];
+ auto it = m_Buckets.find(std::string(InBucket));
+ if (it != m_Buckets.end())
+ {
+ Bucket = &it->second;
+ }
+ else
+ {
+ Bucket = &m_Buckets[std::string(InBucket)];
+ }
}
// Note that since the underlying IoBuffer is retained, the content type is also