From c116b4b55ab23bef00489db9fbff9fae6ba4bba7 Mon Sep 17 00:00:00 2001 From: Samuel Just Date: Wed, 22 Oct 2014 12:40:14 -0700 Subject: [PATCH] shared_cache::add: do not delete value if existed The method contract specifies that we do not want to delete value if we are not inserting it, so do not initialize val at the top of the function to take over value. No current users appear to trip over this problem (FDCache and map_cache). Signed-off-by: Samuel Just --- src/common/shared_cache.hpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/common/shared_cache.hpp b/src/common/shared_cache.hpp index a5079ede6a0ca..0c4832c51647c 100644 --- a/src/common/shared_cache.hpp +++ b/src/common/shared_cache.hpp @@ -209,7 +209,7 @@ public: * @return A reference to the map's value for the given key */ VPtr add(const K& key, V *value, bool *existed = NULL) { - VPtr val(value, Cleanup(this, key)); + VPtr val; list to_release; { Mutex::Locker l(lock); @@ -224,6 +224,7 @@ public: if (existed) *existed = false; + val = VPtr(value, Cleanup(this, key)); weak_refs.insert(actual, make_pair(key, val)); lru_add(key, val, &to_release); } -- 2.39.5