fix clang bug in block-based table reader

Summary:
This is the warning that clang considers a bug and has been causing it to fail:

```
table/block_based_table_reader.cc:240:27: warning: Potential leak of memory pointed to by 'block.value'
    for (; biter.Valid(); biter.Next()) {
                          ^~~~~
```

Actually clang just doesn't have enough knowledge to statically determine it's safe. We can teach it using an assert.
Closes https://github.com/facebook/rocksdb/pull/2779

Differential Revision: D5691225

Pulled By: ajkr

fbshipit-source-id: 3f0d545bf44636953b30ee5243c63239e8f16d8e
main
Andrew Kryczka 7 years ago committed by Facebook Github Bot
parent 7eba54eb9b
commit 19cc66dc4f
  1. 3
      table/block_based_table_reader.cc

@ -257,6 +257,7 @@ class PartitionIndexReader : public IndexReader, public Cleanable {
handle, compression_dict, &block,
is_index);
assert(s.ok() || block.value == nullptr);
if (s.ok() && block.value != nullptr) {
assert(block.cache_handle != nullptr);
if (pin) {
@ -1429,6 +1430,7 @@ Status BlockBasedTable::MaybeLoadDataBlockToCache(
FilePrefetchBuffer* prefetch_buffer, Rep* rep, const ReadOptions& ro,
const BlockHandle& handle, Slice compression_dict,
CachableEntry<Block>* block_entry, bool is_index) {
assert(block_entry != nullptr);
const bool no_io = (ro.read_tier == kBlockCacheTier);
Cache* block_cache = rep->table_options.block_cache.get();
Cache* block_cache_compressed =
@ -1485,6 +1487,7 @@ Status BlockBasedTable::MaybeLoadDataBlockToCache(
}
}
}
assert(s.ok() || block_entry->value == nullptr);
return s;
}

Loading…
Cancel
Save