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

Unified Diff: Source/core/page/HistoryController.cpp

Issue 219413002: Hash iterators: Check for concurrent modification and fix 1 place where it happened (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Fix incorrect use of iterators and remove() in HistoryController.cpp Created 6 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | Source/wtf/HashTable.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/page/HistoryController.cpp
diff --git a/Source/core/page/HistoryController.cpp b/Source/core/page/HistoryController.cpp
index 14aecd73a6b8bd4424e0cab1ed395434a9606136..cf621f75e395a26dce17506ff541211544749c3e 100644
--- a/Source/core/page/HistoryController.cpp
+++ b/Source/core/page/HistoryController.cpp
@@ -83,6 +83,10 @@ HistoryNode::HistoryNode(HistoryEntry* entry, HistoryItem* value, int64_t frameI
void HistoryNode::removeChildren()
{
// FIXME: This is inefficient. Figure out a cleaner way to ensure this HistoryNode isn't cached anywhere.
+ // We need these vectors because you can't remove things from
+ // collections you are iterating over.
+ Vector<uint64_t, 10> framesToRemove;
+ Vector<String, 10> uniqueNamesToRemove;
for (unsigned i = 0; i < m_children.size(); i++) {
m_children[i]->removeChildren();
@@ -90,13 +94,17 @@ void HistoryNode::removeChildren()
HashMap<String, HistoryNode*>::iterator uniqueNamesEnd = m_entry->m_uniqueNamesToItems.end();
for (HashMap<uint64_t, HistoryNode*>::iterator it = m_entry->m_framesToItems.begin(); it != framesEnd; ++it) {
if (it->value == m_children[i])
- m_entry->m_framesToItems.remove(it);
+ framesToRemove.append(it->key);
}
for (HashMap<String, HistoryNode*>::iterator it = m_entry->m_uniqueNamesToItems.begin(); it != uniqueNamesEnd; ++it) {
if (it->value == m_children[i])
- m_entry->m_uniqueNamesToItems.remove(it);
+ uniqueNamesToRemove.append(it->key);
}
}
+ for (unsigned i = 0; i < framesToRemove.size(); i++)
+ m_entry->m_framesToItems.remove(framesToRemove[i]);
+ for (unsigned i = 0; i < uniqueNamesToRemove.size(); i++)
+ m_entry->m_uniqueNamesToItems.remove(uniqueNamesToRemove[i]);
m_children.clear();
}
« no previous file with comments | « no previous file | Source/wtf/HashTable.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698