Fixed the valgrind error in ColumnFamilyTest::CreateAndDropRace

Summary: Fixed the valgrind error in ColumnFamilyTest::CreateAndDropRace

Test Plan: valgrind --error-exitcode=2 --leak-check=full ./column_family_test

Reviewers: kradhakrishnan, rven, anthony, IslamAbdelRahman, sdong

Reviewed By: sdong

Subscribers: dhruba, leveldb

Differential Revision: https://reviews.facebook.net/D51795
This commit is contained in:
Yueh-Hsuan Chiang 2015-12-10 11:53:53 -08:00
parent 9e44629061
commit f0a8e5a2d8

View File

@ -1270,13 +1270,15 @@ const int kMainThreadStartPersistingOptionsFile = 1;
const int kChildThreadFinishDroppingColumnFamily = 2; const int kChildThreadFinishDroppingColumnFamily = 2;
const int kChildThreadWaitingMainThreadPersistOptions = 3; const int kChildThreadWaitingMainThreadPersistOptions = 3;
void DropSingleColumnFamily(ColumnFamilyTest* cf_test, int cf_id, void DropSingleColumnFamily(ColumnFamilyTest* cf_test, int cf_id,
std::vector<Comparator*> comparators) { std::vector<Comparator*>* comparators) {
while (test_stage < kMainThreadStartPersistingOptionsFile) { while (test_stage < kMainThreadStartPersistingOptionsFile) {
Env::Default()->SleepForMicroseconds(100); Env::Default()->SleepForMicroseconds(100);
} }
cf_test->DropColumnFamilies({cf_id}); cf_test->DropColumnFamilies({cf_id});
delete comparators[cf_id]; if ((*comparators)[cf_id]) {
comparators[cf_id] = nullptr; delete (*comparators)[cf_id];
(*comparators)[cf_id] = nullptr;
}
test_stage = kChildThreadFinishDroppingColumnFamily; test_stage = kChildThreadFinishDroppingColumnFamily;
} }
} // namespace } // namespace
@ -1328,15 +1330,19 @@ TEST_F(ColumnFamilyTest, CreateAndDropRace) {
// Start a thread that will drop the first column family // Start a thread that will drop the first column family
// and its comparator // and its comparator
std::thread drop_cf_thread(DropSingleColumnFamily, this, 1, comparators); std::thread drop_cf_thread(DropSingleColumnFamily, this, 1, &comparators);
DropColumnFamilies({2}); DropColumnFamilies({2});
drop_cf_thread.join(); drop_cf_thread.join();
Close(); Close();
Destroy(); Destroy();
rocksdb::SyncPoint::GetInstance()->DisableProcessing(); rocksdb::SyncPoint::GetInstance()->DisableProcessing();
for (auto* comparator : comparators) {
if (comparator) {
delete comparator;
}
}
} }
#endif // !ROCKSDB_LITE #endif // !ROCKSDB_LITE