From f0a8e5a2d85a2dc801111ce49d98a9ece614dc41 Mon Sep 17 00:00:00 2001 From: Yueh-Hsuan Chiang Date: Thu, 10 Dec 2015 11:53:53 -0800 Subject: [PATCH] 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 --- db/column_family_test.cc | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/db/column_family_test.cc b/db/column_family_test.cc index cf77d6d24..b877ea8a1 100644 --- a/db/column_family_test.cc +++ b/db/column_family_test.cc @@ -1270,13 +1270,15 @@ const int kMainThreadStartPersistingOptionsFile = 1; const int kChildThreadFinishDroppingColumnFamily = 2; const int kChildThreadWaitingMainThreadPersistOptions = 3; void DropSingleColumnFamily(ColumnFamilyTest* cf_test, int cf_id, - std::vector comparators) { + std::vector* comparators) { while (test_stage < kMainThreadStartPersistingOptionsFile) { Env::Default()->SleepForMicroseconds(100); } cf_test->DropColumnFamilies({cf_id}); - delete comparators[cf_id]; - comparators[cf_id] = nullptr; + if ((*comparators)[cf_id]) { + delete (*comparators)[cf_id]; + (*comparators)[cf_id] = nullptr; + } test_stage = kChildThreadFinishDroppingColumnFamily; } } // namespace @@ -1328,15 +1330,19 @@ TEST_F(ColumnFamilyTest, CreateAndDropRace) { // Start a thread that will drop the first column family // and its comparator - std::thread drop_cf_thread(DropSingleColumnFamily, this, 1, comparators); + std::thread drop_cf_thread(DropSingleColumnFamily, this, 1, &comparators); DropColumnFamilies({2}); drop_cf_thread.join(); - Close(); Destroy(); rocksdb::SyncPoint::GetInstance()->DisableProcessing(); + for (auto* comparator : comparators) { + if (comparator) { + delete comparator; + } + } } #endif // !ROCKSDB_LITE