Skip to content

Commit

Permalink
Fix LRUCache missing null check on destruct
Browse files Browse the repository at this point in the history
Summary:
Fix LRUCache missing null check on destruct. The check is needed if LRUCache::DisownData is called.
Closes facebook#3920

Differential Revision: D8191631

Pulled By: yiwu-arbug

fbshipit-source-id: d5014f6e49b51692c18a25fb55ece935f5a023c4
  • Loading branch information
Yi Wu authored and facebook-github-bot committed May 29, 2018
1 parent cf826de commit 724855c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
10 changes: 7 additions & 3 deletions cache/lru_cache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -474,10 +474,13 @@ LRUCache::LRUCache(size_t capacity, int num_shard_bits,
}

LRUCache::~LRUCache() {
for (int i = 0; i < num_shards_; i++) {
shards_[i].~LRUCacheShard();
if (shards_ != nullptr) {
assert(num_shards_ > 0);
for (int i = 0; i < num_shards_; i++) {
shards_[i].~LRUCacheShard();
}
port::cacheline_aligned_free(shards_);
}
port::cacheline_aligned_free(shards_);
}

CacheShard* LRUCache::GetShard(int shard) {
Expand All @@ -504,6 +507,7 @@ void LRUCache::DisownData() {
// Do not drop data if compile with ASAN to suppress leak warning.
#ifndef __SANITIZE_ADDRESS__
shards_ = nullptr;
num_shards_ = 0;
#endif // !__SANITIZE_ADDRESS__
}

Expand Down
2 changes: 1 addition & 1 deletion cache/lru_cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ class LRUCache : public ShardedCache {
double GetHighPriPoolRatio();

private:
LRUCacheShard* shards_;
LRUCacheShard* shards_ = nullptr;
int num_shards_ = 0;
};

Expand Down

0 comments on commit 724855c

Please sign in to comment.