From c7432cc3c0848ad4d2a34a3eb40ad94d37477856 Mon Sep 17 00:00:00 2001 From: Peter Dillinger Date: Thu, 4 Jun 2020 15:32:29 -0700 Subject: [PATCH] Fix more defects reported by Coverity Scan (#6935) Summary: Mostly uninitialized values: some probably written before use, but some seem like bugs. Also, destructor needs to be virtual, and possible use-after-free in test Pull Request resolved: https://github.com/facebook/rocksdb/pull/6935 Test Plan: make check Reviewed By: siying Differential Revision: D21885484 Pulled By: pdillinger fbshipit-source-id: e2e7cb0a0cf196f2b55edd16f0634e81f6cc8e08 --- include/rocksdb/perf_context.h | 4 ++-- memtable/memtablerep_bench.cc | 4 ++-- port/port_posix.h | 2 +- table/table_test.cc | 4 ++-- tools/db_bench_tool.cc | 2 +- trace_replay/block_cache_tracer.h | 2 +- utilities/backupable/backupable_db.cc | 1 + 7 files changed, 10 insertions(+), 9 deletions(-) diff --git a/include/rocksdb/perf_context.h b/include/rocksdb/perf_context.h index 03a282f7d..3d61000cc 100644 --- a/include/rocksdb/perf_context.h +++ b/include/rocksdb/perf_context.h @@ -30,10 +30,10 @@ struct PerfContextByLevel { // total number of user key returned (only include keys that are found, does // not include keys that are deleted or merged without a final put - uint64_t user_key_return_count; + uint64_t user_key_return_count = 0; // total nanos spent on reading data from SST files - uint64_t get_from_table_nanos; + uint64_t get_from_table_nanos = 0; uint64_t block_cache_hit_count = 0; // total number of block cache hits uint64_t block_cache_miss_count = 0; // total number of block cache misses diff --git a/memtable/memtablerep_bench.cc b/memtable/memtablerep_bench.cc index b44bc06fd..cbe62cc85 100644 --- a/memtable/memtablerep_bench.cc +++ b/memtable/memtablerep_bench.cc @@ -452,8 +452,8 @@ class Benchmark { MemTableRep* table_; KeyGenerator* key_gen_; uint64_t* sequence_; - uint64_t num_write_ops_per_thread_; - uint64_t num_read_ops_per_thread_; + uint64_t num_write_ops_per_thread_ = 0; + uint64_t num_read_ops_per_thread_ = 0; const uint32_t num_threads_; }; diff --git a/port/port_posix.h b/port/port_posix.h index 065572a8a..a24c7b690 100644 --- a/port/port_posix.h +++ b/port/port_posix.h @@ -124,7 +124,7 @@ class Mutex { friend class CondVar; pthread_mutex_t mu_; #ifndef NDEBUG - bool locked_; + bool locked_ = false; #endif }; diff --git a/table/table_test.cc b/table/table_test.cc index 4b8167371..d7e95ac5e 100644 --- a/table/table_test.cc +++ b/table/table_test.cc @@ -1189,11 +1189,11 @@ class FileChecksumTestHelper { public: FileChecksumTestHelper(bool convert_to_internal_key = false) : convert_to_internal_key_(convert_to_internal_key) { - sink_ = new test::StringSink(); } ~FileChecksumTestHelper() {} void CreateWriteableFile() { + sink_ = new test::StringSink(); file_writer_.reset(test::GetWritableFileWriter(sink_, "" /* don't care */)); } @@ -1291,7 +1291,7 @@ class FileChecksumTestHelper { std::unique_ptr file_reader_; std::unique_ptr table_builder_; stl_wrappers::KVMap kv_map_; - test::StringSink* sink_; + test::StringSink* sink_ = nullptr; static uint64_t checksum_uniq_id_; }; diff --git a/tools/db_bench_tool.cc b/tools/db_bench_tool.cc index f0511d05f..223381098 100644 --- a/tools/db_bench_tool.cc +++ b/tools/db_bench_tool.cc @@ -1851,7 +1851,7 @@ class CombinedStats; class Stats { private: int id_; - uint64_t start_; + uint64_t start_ = 0; uint64_t sine_interval_; uint64_t finish_; double seconds_; diff --git a/trace_replay/block_cache_tracer.h b/trace_replay/block_cache_tracer.h index 5849273dc..9dc62b7fb 100644 --- a/trace_replay/block_cache_tracer.h +++ b/trace_replay/block_cache_tracer.h @@ -220,7 +220,7 @@ class BlockCacheHumanReadableTraceWriter { class BlockCacheTraceReader { public: BlockCacheTraceReader(std::unique_ptr&& reader); - ~BlockCacheTraceReader() = default; + virtual ~BlockCacheTraceReader() = default; // No copy and move. BlockCacheTraceReader(const BlockCacheTraceReader&) = delete; BlockCacheTraceReader& operator=(const BlockCacheTraceReader&) = delete; diff --git a/utilities/backupable/backupable_db.cc b/utilities/backupable/backupable_db.cc index e4eb8e19c..2183ef553 100644 --- a/utilities/backupable/backupable_db.cc +++ b/utilities/backupable/backupable_db.cc @@ -538,6 +538,7 @@ Status BackupEngine::Open(const BackupableDBOptions& options, Env* env, BackupEngineImpl::BackupEngineImpl(const BackupableDBOptions& options, Env* db_env, bool read_only) : initialized_(false), + threads_cpu_priority_(), latest_backup_id_(0), latest_valid_backup_id_(0), stop_backup_(false),