Fix for clang_analyzer build failure in table_test (#7553)
Summary: fix for clang_analyzer build failure in table_test because of potential memory leak of memtable in case of ASSERT failure. Pull Request resolved: https://github.com/facebook/rocksdb/pull/7553 Test Plan: USE_CLANG=1 make analyze; make check -j64 Reviewed By: jay-zhuang Differential Revision: D24295042 Pulled By: akankshamahajan15 fbshipit-source-id: e9ea184367970fff3b520e33f3ceebf28d66ac8d
This commit is contained in:
parent
6528ecc800
commit
850cc0dbed
@ -3661,19 +3661,33 @@ TEST_F(DBHarnessTest, RandomizedLongDB) {
|
|||||||
#endif // ROCKSDB_LITE
|
#endif // ROCKSDB_LITE
|
||||||
#endif // ROCKSDB_VALGRIND_RUN
|
#endif // ROCKSDB_VALGRIND_RUN
|
||||||
|
|
||||||
class MemTableTest : public testing::Test {};
|
class MemTableTest : public testing::Test {
|
||||||
|
public:
|
||||||
TEST_F(MemTableTest, Simple) {
|
MemTableTest() {
|
||||||
InternalKeyComparator cmp(BytewiseComparator());
|
InternalKeyComparator cmp(BytewiseComparator());
|
||||||
auto table_factory = std::make_shared<SkipListFactory>();
|
auto table_factory = std::make_shared<SkipListFactory>();
|
||||||
Options options;
|
options_.memtable_factory = table_factory;
|
||||||
options.memtable_factory = table_factory;
|
ImmutableCFOptions ioptions(options_);
|
||||||
ImmutableCFOptions ioptions(options);
|
wb_ = new WriteBufferManager(options_.db_write_buffer_size);
|
||||||
WriteBufferManager wb(options.db_write_buffer_size);
|
memtable_ = new MemTable(cmp, ioptions, MutableCFOptions(options_), wb_,
|
||||||
MemTable* memtable =
|
|
||||||
new MemTable(cmp, ioptions, MutableCFOptions(options), &wb,
|
|
||||||
kMaxSequenceNumber, 0 /* column_family_id */);
|
kMaxSequenceNumber, 0 /* column_family_id */);
|
||||||
memtable->Ref();
|
memtable_->Ref();
|
||||||
|
}
|
||||||
|
|
||||||
|
~MemTableTest() {
|
||||||
|
delete memtable_->Unref();
|
||||||
|
delete wb_;
|
||||||
|
}
|
||||||
|
|
||||||
|
MemTable* GetMemTable() { return memtable_; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
MemTable* memtable_;
|
||||||
|
Options options_;
|
||||||
|
WriteBufferManager* wb_;
|
||||||
|
};
|
||||||
|
|
||||||
|
TEST_F(MemTableTest, Simple) {
|
||||||
WriteBatch batch;
|
WriteBatch batch;
|
||||||
WriteBatchInternal::SetSequence(&batch, 100);
|
WriteBatchInternal::SetSequence(&batch, 100);
|
||||||
ASSERT_OK(batch.Put(std::string("k1"), std::string("v1")));
|
ASSERT_OK(batch.Put(std::string("k1"), std::string("v1")));
|
||||||
@ -3682,7 +3696,7 @@ TEST_F(MemTableTest, Simple) {
|
|||||||
ASSERT_OK(batch.Put(std::string("largekey"), std::string("vlarge")));
|
ASSERT_OK(batch.Put(std::string("largekey"), std::string("vlarge")));
|
||||||
ASSERT_OK(batch.DeleteRange(std::string("chi"), std::string("xigua")));
|
ASSERT_OK(batch.DeleteRange(std::string("chi"), std::string("xigua")));
|
||||||
ASSERT_OK(batch.DeleteRange(std::string("begin"), std::string("end")));
|
ASSERT_OK(batch.DeleteRange(std::string("begin"), std::string("end")));
|
||||||
ColumnFamilyMemTablesDefault cf_mems_default(memtable);
|
ColumnFamilyMemTablesDefault cf_mems_default(GetMemTable());
|
||||||
ASSERT_TRUE(
|
ASSERT_TRUE(
|
||||||
WriteBatchInternal::InsertInto(&batch, &cf_mems_default, nullptr, nullptr)
|
WriteBatchInternal::InsertInto(&batch, &cf_mems_default, nullptr, nullptr)
|
||||||
.ok());
|
.ok());
|
||||||
@ -3693,10 +3707,10 @@ TEST_F(MemTableTest, Simple) {
|
|||||||
std::unique_ptr<InternalIterator> iter_guard;
|
std::unique_ptr<InternalIterator> iter_guard;
|
||||||
InternalIterator* iter;
|
InternalIterator* iter;
|
||||||
if (i == 0) {
|
if (i == 0) {
|
||||||
iter = memtable->NewIterator(ReadOptions(), &arena);
|
iter = GetMemTable()->NewIterator(ReadOptions(), &arena);
|
||||||
arena_iter_guard.set(iter);
|
arena_iter_guard.set(iter);
|
||||||
} else {
|
} else {
|
||||||
iter = memtable->NewRangeTombstoneIterator(
|
iter = GetMemTable()->NewRangeTombstoneIterator(
|
||||||
ReadOptions(), kMaxSequenceNumber /* read_seq */);
|
ReadOptions(), kMaxSequenceNumber /* read_seq */);
|
||||||
iter_guard.reset(iter);
|
iter_guard.reset(iter);
|
||||||
}
|
}
|
||||||
@ -3710,8 +3724,6 @@ TEST_F(MemTableTest, Simple) {
|
|||||||
iter->Next();
|
iter->Next();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
delete memtable->Unref();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test the empty key
|
// Test the empty key
|
||||||
|
Loading…
x
Reference in New Issue
Block a user