Fix clang failure (#8621)

Summary:
Fixed clang failure because of memory leak

Pull Request resolved: https://github.com/facebook/rocksdb/pull/8621

Test Plan: CircleCI clang job

Reviewed By: pdillinger

Differential Revision: D30114337

Pulled By: akankshamahajan15

fbshipit-source-id: 16572b9bcbaa053c2ab7bc1c344148d0e6f8039c
This commit is contained in:
Akanksha Mahajan 2021-08-04 17:11:47 -07:00 committed by Facebook GitHub Bot
parent c268859aaa
commit a074d46a5a

View File

@ -1501,24 +1501,30 @@ Status BlockBasedTableBuilder::InsertBlockInCache(const Slice& block_contents,
const size_t read_amp_bytes_per_bit = const size_t read_amp_bytes_per_bit =
rep_->table_options.read_amp_bytes_per_bit; rep_->table_options.read_amp_bytes_per_bit;
TBlocklike* block_holder = BlocklikeTraits<TBlocklike>::Create( // TODO akanksha:: Dedup below code by calling
std::move(results), read_amp_bytes_per_bit, // BlockBasedTable::PutDataBlockToCache.
rep_->ioptions.statistics.get(), std::unique_ptr<TBlocklike> block_holder(
false /*rep_->blocks_definitely_zstd_compressed*/, BlocklikeTraits<TBlocklike>::Create(
rep_->table_options.filter_policy.get()); std::move(results), read_amp_bytes_per_bit,
rep_->ioptions.statistics.get(),
false /*rep_->blocks_definitely_zstd_compressed*/,
rep_->table_options.filter_policy.get()));
if (block_holder->own_bytes()) { assert(block_holder->own_bytes());
size_t charge = block_holder->ApproximateMemoryUsage(); size_t charge = block_holder->ApproximateMemoryUsage();
s = block_cache->Insert(key, block_holder, charge, s = block_cache->Insert(
&DeleteEntryCached<TBlocklike>); key, block_holder.get(),
BlocklikeTraits<TBlocklike>::GetCacheItemHelper(block_type), charge,
nullptr, Cache::Priority::LOW);
if (s.ok()) { if (s.ok()) {
BlockBasedTable::UpdateCacheInsertionMetrics( // Release ownership of block_holder.
block_type, nullptr /*get_context*/, charge, s.IsOkOverwritten(), block_holder.release();
rep_->ioptions.stats); BlockBasedTable::UpdateCacheInsertionMetrics(
} else { block_type, nullptr /*get_context*/, charge, s.IsOkOverwritten(),
RecordTick(rep_->ioptions.stats, BLOCK_CACHE_ADD_FAILURES); rep_->ioptions.stats);
} } else {
RecordTick(rep_->ioptions.stats, BLOCK_CACHE_ADD_FAILURES);
} }
} }
return s; return s;