提交 56bbecc3 编写于 作者: S Siying Dong

Merge pull request #867 from SherlockNoMad/CacheFix

Replace malloc with new for LRU Cache Handle
...@@ -74,7 +74,7 @@ struct LRUHandle { ...@@ -74,7 +74,7 @@ struct LRUHandle {
void Free() { void Free() {
assert((refs == 1 && in_cache) || (refs == 0 && !in_cache)); assert((refs == 1 && in_cache) || (refs == 0 && !in_cache));
(*deleter)(key(), value); (*deleter)(key(), value);
free(this); delete[] reinterpret_cast<char*>(this);
} }
}; };
...@@ -390,8 +390,8 @@ Cache::Handle* LRUCache::Insert( ...@@ -390,8 +390,8 @@ Cache::Handle* LRUCache::Insert(
// Allocate the memory here outside of the mutex // Allocate the memory here outside of the mutex
// If the cache is full, we'll have to release it // If the cache is full, we'll have to release it
// It shouldn't happen very often though. // It shouldn't happen very often though.
LRUHandle* e = LRUHandle* e = reinterpret_cast<LRUHandle*>(
reinterpret_cast<LRUHandle*>(malloc(sizeof(LRUHandle) - 1 + key.size())); new char[sizeof(LRUHandle) - 1 + key.size()]);
autovector<LRUHandle*> last_reference_list; autovector<LRUHandle*> last_reference_list;
e->value = value; e->value = value;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册