diff options
Diffstat (limited to 'runtime/base/variant_map.h')
-rw-r--r-- | runtime/base/variant_map.h | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/runtime/base/variant_map.h b/runtime/base/variant_map.h index cf7977edca..c9718fcdd0 100644 --- a/runtime/base/variant_map.h +++ b/runtime/base/variant_map.h @@ -271,8 +271,11 @@ struct VariantMap { // Set a value for a given key, overwriting the previous value if any. template <typename TValue> void Set(const TKey<TValue>& key, const TValue& value) { + // Clone the value first, to protect against &value == GetValuePtr(key). + auto* new_value = new TValue(value); + Remove(key); - storage_map_.insert({{key.Clone(), new TValue(value)}}); + storage_map_.insert({{key.Clone(), new_value}}); } // Set a value for a given key, only if there was no previous value before. |