From ddad40e930427dadca1037a602f53bda25a4834a Mon Sep 17 00:00:00 2001 From: Andres Notzli Date: Tue, 14 Jul 2015 23:12:34 -0700 Subject: [PATCH] Fixed nullptr deref and added assert Summary: Fixes two minor issues in CompactionJob. CompactionJob::Run() dereferences log_buffer_ without a check, so this patch adds an assert in the constructor where log_buffer_ is assigned. compaction_job_stats_ can be null but ProcessKeyValueCompaction was dereferencing it without a check. Test Plan: make && make check Reviewers: sdong, rven, yhchiang, igor Reviewed By: igor Subscribers: dhruba, leveldb Differential Revision: https://reviews.facebook.net/D42231 --- db/compaction_job.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/db/compaction_job.cc b/db/compaction_job.cc index c937684f6..5832ba52c 100644 --- a/db/compaction_job.cc +++ b/db/compaction_job.cc @@ -211,6 +211,7 @@ CompactionJob::CompactionJob( yield_callback_(std::move(yield_callback)), event_logger_(event_logger), paranoid_file_checks_(paranoid_file_checks) { + assert(log_buffer_ != nullptr); ThreadStatusUtil::SetColumnFamily(compact_->compaction->column_family_data()); ThreadStatusUtil::SetThreadOperation(ThreadStatus::OP_COMPACTION); ReportStartedCompaction(compaction); @@ -646,7 +647,7 @@ Status CompactionJob::ProcessKeyValueCompaction(int64_t* imm_micros, last_sequence_for_key = kMaxSequenceNumber; visible_in_snapshot = kMaxSequenceNumber; } else { - if (ikey.type == kTypeDeletion) { + if (compaction_job_stats_ != nullptr && ikey.type == kTypeDeletion) { compaction_job_stats_->num_input_deletion_records++; }