Fix LRUCache missing null check on destruct
Summary: Fix LRUCache missing null check on destruct. The check is needed if LRUCache::DisownData is called. Closes https://github.com/facebook/rocksdb/pull/3920 Differential Revision: D8191631 Pulled By: yiwu-arbug fbshipit-source-id: d5014f6e49b51692c18a25fb55ece935f5a023c4
This commit is contained in:
parent
cf826de3ed
commit
724855c7da
10
cache/lru_cache.cc
vendored
10
cache/lru_cache.cc
vendored
@ -474,10 +474,13 @@ LRUCache::LRUCache(size_t capacity, int num_shard_bits,
|
|||||||
}
|
}
|
||||||
|
|
||||||
LRUCache::~LRUCache() {
|
LRUCache::~LRUCache() {
|
||||||
for (int i = 0; i < num_shards_; i++) {
|
if (shards_ != nullptr) {
|
||||||
shards_[i].~LRUCacheShard();
|
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) {
|
CacheShard* LRUCache::GetShard(int shard) {
|
||||||
@ -504,6 +507,7 @@ void LRUCache::DisownData() {
|
|||||||
// Do not drop data if compile with ASAN to suppress leak warning.
|
// Do not drop data if compile with ASAN to suppress leak warning.
|
||||||
#ifndef __SANITIZE_ADDRESS__
|
#ifndef __SANITIZE_ADDRESS__
|
||||||
shards_ = nullptr;
|
shards_ = nullptr;
|
||||||
|
num_shards_ = 0;
|
||||||
#endif // !__SANITIZE_ADDRESS__
|
#endif // !__SANITIZE_ADDRESS__
|
||||||
}
|
}
|
||||||
|
|
||||||
|
2
cache/lru_cache.h
vendored
2
cache/lru_cache.h
vendored
@ -295,7 +295,7 @@ class LRUCache : public ShardedCache {
|
|||||||
double GetHighPriPoolRatio();
|
double GetHighPriPoolRatio();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
LRUCacheShard* shards_;
|
LRUCacheShard* shards_ = nullptr;
|
||||||
int num_shards_ = 0;
|
int num_shards_ = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user