diff --git a/cache/lru_cache.cc b/cache/lru_cache.cc index 06d223f3a..c8e4d29ba 100644 --- a/cache/lru_cache.cc +++ b/cache/lru_cache.cc @@ -386,7 +386,7 @@ Status LRUCacheShard::InsertItem(LRUHandle* e, LRUHandle** handle, last_reference_list.push_back(e); } else { if (free_handle_on_fail) { - delete[] reinterpret_cast(e); + free(e); *handle = nullptr; } s = Status::MemoryLimit("Insert failed due to LRU cache being full."); @@ -559,8 +559,7 @@ LRUHandle* LRUCacheShard::Lookup(const Slice& key, uint32_t hash, secondary_cache_->Lookup(key, create_cb, wait, found_dummy_entry, is_in_sec_cache); if (secondary_handle != nullptr) { - e = reinterpret_cast( - new char[sizeof(LRUHandle) - 1 + key.size()]); + e = static_cast(malloc(sizeof(LRUHandle) - 1 + key.size())); e->m_flags = 0; e->im_flags = 0; @@ -683,8 +682,8 @@ Status LRUCacheShard::Insert(const Slice& key, uint32_t hash, void* value, // Allocate the memory here outside of the mutex. // If the cache is full, we'll have to release it. // It shouldn't happen very often though. - LRUHandle* e = reinterpret_cast( - new char[sizeof(LRUHandle) - 1 + key.size()]); + LRUHandle* e = + static_cast(malloc(sizeof(LRUHandle) - 1 + key.size())); e->value = value; e->m_flags = 0; diff --git a/cache/lru_cache.h b/cache/lru_cache.h index ff5d36467..99b2f2b20 100644 --- a/cache/lru_cache.h +++ b/cache/lru_cache.h @@ -212,6 +212,7 @@ struct LRUHandle { void Free() { assert(refs == 0); + if (!IsSecondaryCacheCompatible() && info_.deleter) { (*info_.deleter)(key(), value); } else if (IsSecondaryCacheCompatible()) { @@ -226,7 +227,8 @@ struct LRUHandle { (*info_.helper->del_cb)(key(), value); } } - delete[] reinterpret_cast(this); + + free(this); } inline size_t CalcuMetaCharge(