Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(278)

Side by Side Diff: third_party/WebKit/Source/core/fetch/MemoryCache.cpp

Issue 1537343002: Fix null dereference on MemoryCache. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 Copyright (C) 1998 Lars Knoll (knoll@mpi-hd.mpg.de) 2 Copyright (C) 1998 Lars Knoll (knoll@mpi-hd.mpg.de)
3 Copyright (C) 2001 Dirk Mueller (mueller@kde.org) 3 Copyright (C) 2001 Dirk Mueller (mueller@kde.org)
4 Copyright (C) 2002 Waldo Bastian (bastian@kde.org) 4 Copyright (C) 2002 Waldo Bastian (bastian@kde.org)
5 Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. 5 Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
6 6
7 This library is free software; you can redistribute it and/or 7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public 8 modify it under the terms of the GNU Library General Public
9 License as published by the Free Software Foundation; either 9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version. 10 version 2 of the License, or (at your option) any later version.
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 // Destroy our decoded data. This will remove us from 340 // Destroy our decoded data. This will remove us from
341 // m_liveDecodedResources, and possibly move us to a different 341 // m_liveDecodedResources, and possibly move us to a different
342 // LRU list in m_allResources. 342 // LRU list in m_allResources.
343 current->m_resource->prune(); 343 current->m_resource->prune();
344 344
345 if (targetSize && m_deadSize <= targetSize) 345 if (targetSize && m_deadSize <= targetSize)
346 return; 346 return;
347 } 347 }
348 // Decoded data may reference other resources. Stop iterating if 'pr evious' somehow got 348 // Decoded data may reference other resources. Stop iterating if 'pr evious' somehow got
349 // kicked out of cache during destroyDecodedData(). 349 // kicked out of cache during destroyDecodedData().
350 if (previous && !contains(previous->m_resource.get())) 350 if (!previous || !previous->m_resource || !contains(previous->m_reso urce.get()))
351 break; 351 break;
352 current = previous; 352 current = previous;
353 } 353 }
354 354
355 // Now evict objects from this queue. 355 // Now evict objects from this queue.
356 current = m_allResources[i].m_tail; 356 current = m_allResources[i].m_tail;
357 while (current) { 357 while (current) {
358 MemoryCacheEntry* previous = current->m_previousInAllResourcesList; 358 MemoryCacheEntry* previous = current->m_previousInAllResourcesList;
359 if (previous) { 359 if (previous) {
360 // These release assertions are for investigating crashes and 360 // These release assertions are for investigating crashes and
361 // should be removed shortly. 361 // should be removed shortly.
362 RELEASE_ASSERT(previous->m_resource); 362 RELEASE_ASSERT(previous->m_resource);
363 RELEASE_ASSERT(contains(previous->m_resource.get())); 363 RELEASE_ASSERT(contains(previous->m_resource.get()));
364 } 364 }
365 if (!current->m_resource->hasClients() && !current->m_resource->isPr eloaded() 365 if (!current->m_resource->hasClients() && !current->m_resource->isPr eloaded()
366 && !current->m_resource->isCacheValidator() && current->m_resour ce->canDelete() 366 && !current->m_resource->isCacheValidator() && current->m_resour ce->canDelete()
367 && current->m_resource->type() != Resource::MainResource) { 367 && current->m_resource->type() != Resource::MainResource) {
368 // Main Resources in the cache are only substitue data that was 368 // Main Resources in the cache are only substitue data that was
369 // precached and should not be evicted. 369 // precached and should not be evicted.
370 bool wasEvicted = evict(current); 370 bool wasEvicted = evict(current);
371 ASSERT_UNUSED(wasEvicted, wasEvicted); 371 ASSERT_UNUSED(wasEvicted, wasEvicted);
372 if (targetSize && m_deadSize <= targetSize) 372 if (targetSize && m_deadSize <= targetSize)
373 return; 373 return;
374 } 374 }
375 if (previous && !contains(previous->m_resource.get())) 375 if (!previous || !previous->m_resource || !contains(previous->m_reso urce.get()))
376 break; 376 break;
377 current = previous; 377 current = previous;
378 } 378 }
379 379
380 // Shrink the vector back down so we don't waste time inspecting 380 // Shrink the vector back down so we don't waste time inspecting
381 // empty LRU lists on future prunes. 381 // empty LRU lists on future prunes.
382 if (m_allResources[i].m_head) 382 if (m_allResources[i].m_head)
383 canShrinkLRULists = false; 383 canShrinkLRULists = false;
384 else if (canShrinkLRULists) 384 else if (canShrinkLRULists)
385 m_allResources.resize(i); 385 m_allResources.resize(i);
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after
784 void MemoryCache::onMemoryDump(WebMemoryDumpLevelOfDetail levelOfDetail, WebProc essMemoryDump* memoryDump) 784 void MemoryCache::onMemoryDump(WebMemoryDumpLevelOfDetail levelOfDetail, WebProc essMemoryDump* memoryDump)
785 { 785 {
786 for (const auto& resourceMapIter : m_resourceMaps) { 786 for (const auto& resourceMapIter : m_resourceMaps) {
787 for (const auto& resourceIter : *resourceMapIter.value) { 787 for (const auto& resourceIter : *resourceMapIter.value) {
788 Resource* resource = resourceIter.value->m_resource.get(); 788 Resource* resource = resourceIter.value->m_resource.get();
789 resource->onMemoryDump(levelOfDetail, memoryDump); 789 resource->onMemoryDump(levelOfDetail, memoryDump);
790 } 790 }
791 } 791 }
792 } 792 }
793 793
794 bool MemoryCache::isInSameLRUListForTest(const Resource* x, const Resource* y)
795 {
796 MemoryCacheEntry* ex = getEntryForResource(x);
797 MemoryCacheEntry* ey = getEntryForResource(y);
798 ASSERT(ex);
799 ASSERT(ey);
800 return lruListFor(ex->m_accessCount, x->size()) == lruListFor(ey->m_accessCo unt, y->size());
801 }
802
794 void MemoryCache::registerLiveResource(Resource& resource) 803 void MemoryCache::registerLiveResource(Resource& resource)
795 { 804 {
796 #if ENABLE(OILPAN) 805 #if ENABLE(OILPAN)
797 ASSERT(!m_liveResources.contains(&resource)); 806 ASSERT(!m_liveResources.contains(&resource));
798 m_liveResources.add(&resource); 807 m_liveResources.add(&resource);
799 #endif 808 #endif
800 } 809 }
801 810
802 void MemoryCache::unregisterLiveResource(Resource& resource) 811 void MemoryCache::unregisterLiveResource(Resource& resource)
803 { 812 {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
845 printf("(%.1fK, %.1fK, %uA, %dR, %d, %d); ", currentResource->de codedSize() / 1024.0f, (currentResource->encodedSize() + currentResource->overhe adSize()) / 1024.0f, current->m_accessCount, currentResource->hasClients(), curr entResource->isPurgeable(), currentResource->wasPurged()); 854 printf("(%.1fK, %.1fK, %uA, %dR, %d, %d); ", currentResource->de codedSize() / 1024.0f, (currentResource->encodedSize() + currentResource->overhe adSize()) / 1024.0f, current->m_accessCount, currentResource->hasClients(), curr entResource->isPurgeable(), currentResource->wasPurged());
846 855
847 current = current->m_previousInAllResourcesList; 856 current = current->m_previousInAllResourcesList;
848 } 857 }
849 } 858 }
850 } 859 }
851 860
852 #endif // MEMORY_CACHE_STATS 861 #endif // MEMORY_CACHE_STATS
853 862
854 } // namespace blink 863 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/fetch/MemoryCache.h ('k') | third_party/WebKit/Source/core/fetch/StyleSheetResource.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698