| Index: net/disk_cache/backend_unittest.cc
|
| diff --git a/net/disk_cache/backend_unittest.cc b/net/disk_cache/backend_unittest.cc
|
| index 65f8cb0bae6ee75ca4bb1298fd98018878447a17..4114d409aa736737f1a480b695de1180710a46a5 100644
|
| --- a/net/disk_cache/backend_unittest.cc
|
| +++ b/net/disk_cache/backend_unittest.cc
|
| @@ -82,7 +82,7 @@ class DiskCacheBackendTest : public DiskCacheTestWithCache {
|
|
|
| bool CreateSetOfRandomEntries(std::set<std::string>* key_pool);
|
| bool EnumerateAndMatchKeys(int max_to_open,
|
| - void** iter,
|
| + disk_cache::Backend::Iterator* iter,
|
| std::set<std::string>* keys_to_match,
|
| size_t* count);
|
|
|
| @@ -258,7 +258,7 @@ bool DiskCacheBackendTest::CreateSetOfRandomEntries(
|
| // OpenNextEntry stops returning net::OK.
|
| bool DiskCacheBackendTest::EnumerateAndMatchKeys(
|
| int max_to_open,
|
| - void** iter,
|
| + disk_cache::Backend::Iterator* iter,
|
| std::set<std::string>* keys_to_match,
|
| size_t* count) {
|
| disk_cache::Entry* entry;
|
| @@ -1239,7 +1239,7 @@ void DiskCacheBackendTest::BackendEnumerations() {
|
| Time final = Time::Now();
|
|
|
| disk_cache::Entry* entry;
|
| - void* iter = NULL;
|
| + disk_cache::Backend::Iterator iter;
|
| int count = 0;
|
| Time last_modified[kNumEntries];
|
| Time last_used[kNumEntries];
|
| @@ -1257,7 +1257,7 @@ void DiskCacheBackendTest::BackendEnumerations() {
|
| };
|
| EXPECT_EQ(kNumEntries, count);
|
|
|
| - iter = NULL;
|
| + iter.reset();
|
| count = 0;
|
| // The previous enumeration should not have changed the timestamps.
|
| while (OpenNextEntry(&iter, &entry) == net::OK) {
|
| @@ -1311,7 +1311,7 @@ void DiskCacheBackendTest::BackendEnumerations2() {
|
| // Make sure that the timestamp is not the same.
|
| AddDelay();
|
| ASSERT_EQ(net::OK, OpenEntry(second, &entry1));
|
| - void* iter = NULL;
|
| + disk_cache::Backend::Iterator iter;
|
| ASSERT_EQ(net::OK, OpenNextEntry(&iter, &entry2));
|
| EXPECT_EQ(entry2->GetKey(), second);
|
|
|
| @@ -1323,7 +1323,7 @@ void DiskCacheBackendTest::BackendEnumerations2() {
|
| ASSERT_EQ(net::OK, OpenNextEntry(&iter, &entry2));
|
| EXPECT_EQ(entry2->GetKey(), first);
|
| entry2->Close();
|
| - cache_->EndEnumeration(&iter);
|
| + iter.reset();
|
|
|
| // Modify the oldest entry and get the newest element.
|
| ASSERT_EQ(net::OK, OpenEntry(first, &entry1));
|
| @@ -1338,7 +1338,6 @@ void DiskCacheBackendTest::BackendEnumerations2() {
|
|
|
| entry1->Close();
|
| entry2->Close();
|
| - cache_->EndEnumeration(&iter);
|
| }
|
|
|
| TEST_F(DiskCacheBackendTest, Enumerations2) {
|
| @@ -1393,11 +1392,10 @@ TEST_F(DiskCacheBackendTest, ShaderCacheEnumerationReadData) {
|
| EXPECT_EQ(kSize, ReadData(entry1, 0, 0, buffer1.get(), kSize));
|
| entry1->Close();
|
|
|
| - void* iter = NULL;
|
| + disk_cache::Backend::Iterator iter;
|
| ASSERT_EQ(net::OK, OpenNextEntry(&iter, &entry2));
|
| EXPECT_EQ(entry2->GetKey(), second);
|
| entry2->Close();
|
| - cache_->EndEnumeration(&iter);
|
| }
|
|
|
| #if !defined(LEAK_SANITIZER)
|
| @@ -1426,7 +1424,7 @@ void DiskCacheBackendTest::BackendInvalidEntryEnumeration() {
|
|
|
| SimulateCrash();
|
|
|
| - void* iter = NULL;
|
| + disk_cache::Backend::Iterator iter;
|
| int count = 0;
|
| while (OpenNextEntry(&iter, &entry) == net::OK) {
|
| ASSERT_TRUE(NULL != entry);
|
| @@ -1468,8 +1466,7 @@ void DiskCacheBackendTest::BackendFixEnumerators() {
|
| EXPECT_EQ(kNumEntries, cache_->GetEntryCount());
|
|
|
| disk_cache::Entry *entry1, *entry2;
|
| - void* iter1 = NULL;
|
| - void* iter2 = NULL;
|
| + disk_cache::Backend::Iterator iter1, iter2;
|
| ASSERT_EQ(net::OK, OpenNextEntry(&iter1, &entry1));
|
| ASSERT_TRUE(NULL != entry1);
|
| entry1->Close();
|
| @@ -1501,9 +1498,6 @@ void DiskCacheBackendTest::BackendFixEnumerators() {
|
| ASSERT_EQ(net::OK, OpenNextEntry(&iter2, &entry2));
|
| ASSERT_TRUE(NULL != entry2);
|
| entry2->Close();
|
| -
|
| - cache_->EndEnumeration(&iter1);
|
| - cache_->EndEnumeration(&iter2);
|
| }
|
|
|
| TEST_F(DiskCacheBackendTest, FixEnumerators) {
|
| @@ -2029,7 +2023,7 @@ void DiskCacheBackendTest::BackendInvalidEntry3() {
|
| InitCache();
|
|
|
| disk_cache::Entry* entry;
|
| - void* iter = NULL;
|
| + disk_cache::Backend::Iterator iter;
|
| while (OpenNextEntry(&iter, &entry) == net::OK) {
|
| entry->Close();
|
| }
|
| @@ -2174,7 +2168,7 @@ void DiskCacheBackendTest::BackendInvalidEntry7() {
|
| EXPECT_EQ(1, cache_->GetEntryCount());
|
|
|
| // We should delete the cache. The list still has a corrupt node.
|
| - void* iter = NULL;
|
| + disk_cache::Backend::Iterator iter;
|
| EXPECT_NE(net::OK, OpenNextEntry(&iter, &entry));
|
| FlushQueueForTest();
|
| EXPECT_EQ(0, cache_->GetEntryCount());
|
| @@ -2218,7 +2212,7 @@ void DiskCacheBackendTest::BackendInvalidEntry8() {
|
| EXPECT_EQ(1, cache_->GetEntryCount());
|
|
|
| // We should not delete the cache.
|
| - void* iter = NULL;
|
| + disk_cache::Backend::Iterator iter;
|
| ASSERT_EQ(net::OK, OpenNextEntry(&iter, &entry));
|
| entry->Close();
|
| EXPECT_NE(net::OK, OpenNextEntry(&iter, &entry));
|
| @@ -2268,7 +2262,7 @@ void DiskCacheBackendTest::BackendInvalidEntry9(bool eviction) {
|
| } else {
|
| // We should detect the problem through the list, but we should not delete
|
| // the entry, just fail the iteration.
|
| - void* iter = NULL;
|
| + disk_cache::Backend::Iterator iter;
|
| EXPECT_NE(net::OK, OpenNextEntry(&iter, &entry));
|
|
|
| // Now a full iteration will work, and return one entry.
|
| @@ -2345,7 +2339,7 @@ void DiskCacheBackendTest::BackendInvalidEntry10(bool eviction) {
|
| // Detection order: third -> second -> first.
|
| // We should detect the problem through the list, but we should not delete
|
| // the entry.
|
| - void* iter = NULL;
|
| + disk_cache::Backend::Iterator iter;
|
| ASSERT_EQ(net::OK, OpenNextEntry(&iter, &entry));
|
| entry->Close();
|
| ASSERT_EQ(net::OK, OpenNextEntry(&iter, &entry));
|
| @@ -2412,7 +2406,7 @@ void DiskCacheBackendTest::BackendInvalidEntry11(bool eviction) {
|
| // Detection order: third -> second.
|
| // We should detect the problem through the list, but we should not delete
|
| // the entry, just fail the iteration.
|
| - void* iter = NULL;
|
| + disk_cache::Backend::Iterator iter;
|
| ASSERT_EQ(net::OK, OpenNextEntry(&iter, &entry));
|
| entry->Close();
|
| EXPECT_NE(net::OK, OpenNextEntry(&iter, &entry));
|
| @@ -2500,7 +2494,7 @@ TEST_F(DiskCacheBackendTest, NewEvictionInvalidRankings2) {
|
| // If the LRU is corrupt, we delete the cache.
|
| void DiskCacheBackendTest::BackendInvalidRankings() {
|
| disk_cache::Entry* entry;
|
| - void* iter = NULL;
|
| + disk_cache::Backend::Iterator iter;
|
| ASSERT_EQ(net::OK, OpenNextEntry(&iter, &entry));
|
| entry->Close();
|
| EXPECT_EQ(2, cache_->GetEntryCount());
|
| @@ -2545,7 +2539,7 @@ TEST_F(DiskCacheBackendTest, NewEvictionInvalidRankingsFailure) {
|
| // If the LRU is corrupt and we have open entries, we disable the cache.
|
| void DiskCacheBackendTest::BackendDisable() {
|
| disk_cache::Entry *entry1, *entry2;
|
| - void* iter = NULL;
|
| + disk_cache::Backend::Iterator iter;
|
| ASSERT_EQ(net::OK, OpenNextEntry(&iter, &entry1));
|
|
|
| EXPECT_NE(net::OK, OpenNextEntry(&iter, &entry2));
|
| @@ -2596,7 +2590,7 @@ void DiskCacheBackendTest::BackendDisable2() {
|
| EXPECT_EQ(8, cache_->GetEntryCount());
|
|
|
| disk_cache::Entry* entry;
|
| - void* iter = NULL;
|
| + disk_cache::Backend::Iterator iter;
|
| int count = 0;
|
| while (OpenNextEntry(&iter, &entry) == net::OK) {
|
| ASSERT_TRUE(NULL != entry);
|
| @@ -2644,7 +2638,7 @@ TEST_F(DiskCacheBackendTest, NewEvictionDisableFailure2) {
|
| // If the index size changes when we disable the cache, we should not crash.
|
| void DiskCacheBackendTest::BackendDisable3() {
|
| disk_cache::Entry *entry1, *entry2;
|
| - void* iter = NULL;
|
| + disk_cache::Backend::Iterator iter;
|
| EXPECT_EQ(2, cache_->GetEntryCount());
|
| ASSERT_EQ(net::OK, OpenNextEntry(&iter, &entry1));
|
| entry1->Close();
|
| @@ -2678,7 +2672,7 @@ TEST_F(DiskCacheBackendTest, NewEvictionDisableSuccess3) {
|
| // If we disable the cache, already open entries should work as far as possible.
|
| void DiskCacheBackendTest::BackendDisable4() {
|
| disk_cache::Entry *entry1, *entry2, *entry3, *entry4;
|
| - void* iter = NULL;
|
| + disk_cache::Backend::Iterator iter;
|
| ASSERT_EQ(net::OK, OpenNextEntry(&iter, &entry1));
|
|
|
| char key2[2000];
|
| @@ -3419,16 +3413,16 @@ TEST_F(DiskCacheBackendTest, SimpleCacheEnumerationBasics) {
|
|
|
| // Check that enumeration returns all entries.
|
| std::set<std::string> keys_to_match(key_pool);
|
| - void* iter = NULL;
|
| + disk_cache::Backend::Iterator iter;
|
| size_t count = 0;
|
| ASSERT_TRUE(EnumerateAndMatchKeys(-1, &iter, &keys_to_match, &count));
|
| - cache_->EndEnumeration(&iter);
|
| + iter.reset();
|
| EXPECT_EQ(key_pool.size(), count);
|
| EXPECT_TRUE(keys_to_match.empty());
|
|
|
| // Check that opening entries does not affect enumeration.
|
| keys_to_match = key_pool;
|
| - iter = NULL;
|
| + iter.reset();
|
| count = 0;
|
| disk_cache::Entry* entry_opened_before;
|
| ASSERT_EQ(net::OK, OpenEntry(*(key_pool.begin()), &entry_opened_before));
|
| @@ -3441,7 +3435,7 @@ TEST_F(DiskCacheBackendTest, SimpleCacheEnumerationBasics) {
|
| ASSERT_EQ(net::OK,
|
| OpenEntry(*(keys_to_match.begin()), &entry_opened_middle));
|
| ASSERT_TRUE(EnumerateAndMatchKeys(-1, &iter, &keys_to_match, &count));
|
| - cache_->EndEnumeration(&iter);
|
| + iter.reset();
|
| entry_opened_before->Close();
|
| entry_opened_middle->Close();
|
|
|
| @@ -3459,7 +3453,7 @@ TEST_F(DiskCacheBackendTest, SimpleCacheEnumerationWhileDoomed) {
|
|
|
| // Check that enumeration returns all entries but the doomed one.
|
| std::set<std::string> keys_to_match(key_pool);
|
| - void* iter = NULL;
|
| + disk_cache::Backend::Iterator iter;
|
| size_t count = 0;
|
| ASSERT_TRUE(EnumerateAndMatchKeys(key_pool.size()/2,
|
| &iter,
|
| @@ -3471,7 +3465,7 @@ TEST_F(DiskCacheBackendTest, SimpleCacheEnumerationWhileDoomed) {
|
| keys_to_match.erase(key_to_delete);
|
| key_pool.erase(key_to_delete);
|
| ASSERT_TRUE(EnumerateAndMatchKeys(-1, &iter, &keys_to_match, &count));
|
| - cache_->EndEnumeration(&iter);
|
| + iter.reset();
|
|
|
| EXPECT_EQ(key_pool.size(), count);
|
| EXPECT_TRUE(keys_to_match.empty());
|
| @@ -3507,13 +3501,31 @@ TEST_F(DiskCacheBackendTest, SimpleCacheEnumerationCorruption) {
|
|
|
| // Check that enumeration returns all entries but the corrupt one.
|
| std::set<std::string> keys_to_match(key_pool);
|
| - void* iter = NULL;
|
| + disk_cache::Backend::Iterator iter;
|
| size_t count = 0;
|
| ASSERT_TRUE(EnumerateAndMatchKeys(-1, &iter, &keys_to_match, &count));
|
| - cache_->EndEnumeration(&iter);
|
| + iter.reset();
|
|
|
| EXPECT_EQ(key_pool.size(), count);
|
| EXPECT_TRUE(keys_to_match.empty());
|
| }
|
|
|
| +// Tests that enumerations don't leak memory when the backend is destructed
|
| +// mid-enumeration.
|
| +TEST_F(DiskCacheBackendTest, SimpleCacheEnumerationDestruction) {
|
| + SetSimpleCacheMode();
|
| + InitCache();
|
| + std::set<std::string> key_pool;
|
| + ASSERT_TRUE(CreateSetOfRandomEntries(&key_pool));
|
| +
|
| + disk_cache::Backend::Iterator iter;
|
| + disk_cache::Entry* entry = NULL;
|
| + ASSERT_EQ(net::OK, OpenNextEntry(&iter, &entry));
|
| + EXPECT_TRUE(entry);
|
| + disk_cache::ScopedEntryPtr entry_closer(entry);
|
| +
|
| + cache_.reset();
|
| + // This test passes if we don't leak memory.
|
| +}
|
| +
|
| #endif // defined(OS_POSIX)
|
|
|