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 <sam.just@inktank.com>
* @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<VPtr> to_release;
{
Mutex::Locker l(lock);
if (existed)
*existed = false;
+ val = VPtr(value, Cleanup(this, key));
weak_refs.insert(actual, make_pair(key, val));
lru_add(key, val, &to_release);
}