diff options
author | phajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-16 10:16:45 +0000 |
---|---|---|
committer | phajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-16 10:16:45 +0000 |
commit | 6ae73ea5e679a176482fe649336e1b79cbda3eff (patch) | |
tree | 377e5d3567527cf137ddcf75c1ecd334662195fd /base | |
parent | 881ac4bde2e5acc19a81b623f2b8b32ba60f1a70 (diff) | |
download | chromium_src-6ae73ea5e679a176482fe649336e1b79cbda3eff.zip chromium_src-6ae73ea5e679a176482fe649336e1b79cbda3eff.tar.gz chromium_src-6ae73ea5e679a176482fe649336e1b79cbda3eff.tar.bz2 |
Merge 39084 - Correctly recognize emptiness of IDMap.
This prevents a leak of RenderProcessHost, and possibly other
bad bugs.
TEST=Added to base_unittests; also existing browser and unit tests.
BUG=35571
Review URL: http://codereview.chromium.org/604048
TBR=brettw@chromium.org
Review URL: http://codereview.chromium.org/601078
git-svn-id: svn://svn.chromium.org/chrome/branches/307/src@39086 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r-- | base/id_map.h | 4 | ||||
-rw-r--r-- | base/id_map_unittest.cc | 17 |
2 files changed, 16 insertions, 5 deletions
diff --git a/base/id_map.h b/base/id_map.h index b108dbd..acfba42 100644 --- a/base/id_map.h +++ b/base/id_map.h @@ -82,7 +82,7 @@ class IDMap { } bool IsEmpty() const { - return data_.empty(); + return size() == 0u; } T* Lookup(KeyType id) const { @@ -93,7 +93,7 @@ class IDMap { } size_t size() const { - return data_.size(); + return data_.size() - removed_ids_.size(); } // It is safe to remove elements from the map during iteration. All iterators diff --git a/base/id_map_unittest.cc b/base/id_map_unittest.cc index 58abf96..54475b6 100644 --- a/base/id_map_unittest.cc +++ b/base/id_map_unittest.cc @@ -67,10 +67,21 @@ TEST_F(IDMapTest, IteratorRemainsValidWhenRemovingCurrentElement) { map.Add(&obj2); map.Add(&obj3); - for (IDMap<TestObject>::const_iterator iter(&map); - !iter.IsAtEnd(); iter.Advance()) { - map.Remove(iter.GetCurrentKey()); + { + IDMap<TestObject>::const_iterator iter(&map); + while (!iter.IsAtEnd()) { + map.Remove(iter.GetCurrentKey()); + iter.Advance(); + } + + // Test that while an iterator is still in scope, we get the map emptiness + // right (http://crbug.com/35571). + EXPECT_TRUE(map.IsEmpty()); + EXPECT_EQ(0U, map.size()); } + + EXPECT_TRUE(map.IsEmpty()); + EXPECT_EQ(0U, map.size()); } TEST_F(IDMapTest, IteratorRemainsValidWhenRemovingOtherElements) { |