From 714ce5041dedbfcaf964e7cf67999921110cd134 Mon Sep 17 00:00:00 2001 From: Baptiste Lemaire Date: Tue, 6 Jul 2021 18:47:59 -0700 Subject: [PATCH] Fix clang_analyzer failure (#8492) Summary: Previously, the following command: ```USE_CLANG=1 TEST_TMPDIR=/dev/shm/rocksdb OPT=-g make -j$(nproc) analyze``` was raising an error/warning the new_mem could potentially be a `nullptr`. This error appeared due to code changes from https://github.com/facebook/rocksdb/issues/8454, including an if-statement containing "`... && new_mem != nullptr && ...`", which made the analyzer believe that past this `if`-statement, a `new_mem==nullptr` was a possible scenario. This code patch simply introduces `assert`s and removes this condition in the `if`-statement. Pull Request resolved: https://github.com/facebook/rocksdb/pull/8492 Reviewed By: jay-zhuang Differential Revision: D29571275 Pulled By: bjlemaire fbshipit-source-id: 75d72246b70ebbbae7dea11ccb5778686d8bcbea --- db/db_impl/db_impl_write.cc | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/db/db_impl/db_impl_write.cc b/db/db_impl/db_impl_write.cc index acccbff23..bbed637c1 100644 --- a/db/db_impl/db_impl_write.cc +++ b/db/db_impl/db_impl_write.cc @@ -2113,14 +2113,13 @@ Status DBImpl::SwitchMemtable(ColumnFamilyData* cfd, WriteContext* context) { } cfd->mem()->SetNextLogNumber(logfile_number_); - + assert(new_mem != nullptr); // By default, it is assumed that the 'old' memtable // will be added to the Imm memtable list and will therefore // contribute to the Imm memory footprint. bool noImmMemoryContribution = false; // If MemPurge activated, purge and delete current memtable. if (immutable_db_options_.experimental_allow_mempurge && - (new_mem != nullptr) && ((cfd->GetFlushReason() == FlushReason::kOthers) || (cfd->GetFlushReason() == FlushReason::kManualFlush))) { Status mempurge_s = MemPurge(cfd, new_mem); @@ -2135,9 +2134,8 @@ Status DBImpl::SwitchMemtable(ColumnFamilyData* cfd, WriteContext* context) { noImmMemoryContribution = true; } else { // If mempurge failed, go back to regular mem->imm->flush workflow. - if (new_mem) { - delete new_mem; - } + assert(new_mem != nullptr); + delete new_mem; SuperVersion* new_superversion = context->superversion_context.new_superversion.release(); if (new_superversion != nullptr) { @@ -2145,6 +2143,7 @@ Status DBImpl::SwitchMemtable(ColumnFamilyData* cfd, WriteContext* context) { } SequenceNumber seq = versions_->LastSequence(); new_mem = cfd->ConstructNewMemtable(mutable_cf_options, seq); + assert(new_mem != nullptr); context->superversion_context.NewSuperVersion(); cfd->imm()->Add(cfd->mem(), &context->memtables_to_free_); }