summaryrefslogtreecommitdiff
path: root/gold/fileread.cc
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@google.com>2007-12-10 22:55:31 +0000
committerIan Lance Taylor <iant@google.com>2007-12-10 22:55:31 +0000
commitfcf29b24159e899f306070e6b827231849c80387 (patch)
treed1054f30b9868f08bfcbfee218680856c95e345d /gold/fileread.cc
parentb7fca9900061de1830d30f0c782e677a5ad277f7 (diff)
downloadbinutils-gdb-fcf29b24159e899f306070e6b827231849c80387.tar.gz
Keep views on views_ list so that they can be found again.
Diffstat (limited to 'gold/fileread.cc')
-rw-r--r--gold/fileread.cc32
1 files changed, 19 insertions, 13 deletions
diff --git a/gold/fileread.cc b/gold/fileread.cc
index 1e3b4638f68..9579f0f5dd4 100644
--- a/gold/fileread.cc
+++ b/gold/fileread.cc
@@ -331,34 +331,40 @@ File_read::get_lasting_view(off_t start, off_t size, bool cache)
void
File_read::clear_views(bool destroying)
{
- for (Views::iterator p = this->views_.begin();
- p != this->views_.end();
- ++p)
+ Views::iterator p = this->views_.begin();
+ while (p != this->views_.end())
{
if (!p->second->is_locked()
&& (destroying || !p->second->should_cache()))
- delete p->second;
+ {
+ delete p->second;
+
+ // map::erase invalidates only the iterator to the deleted
+ // element.
+ Views::iterator pe = p;
+ ++p;
+ this->views_.erase(pe);
+ }
else
{
gold_assert(!destroying);
- this->saved_views_.push_back(p->second);
+ ++p;
}
}
- this->views_.clear();
- Saved_views::iterator p = this->saved_views_.begin();
- while (p != this->saved_views_.end())
+ Saved_views::iterator q = this->saved_views_.begin();
+ while (q != this->saved_views_.end())
{
- if (!(*p)->is_locked()
- && (destroying || !(*p)->should_cache()))
+ if (!(*q)->is_locked()
+ && (destroying || !(*q)->should_cache()))
{
- delete *p;
- p = this->saved_views_.erase(p);
+ delete *q;
+ q = this->saved_views_.erase(q);
}
else
{
gold_assert(!destroying);
- ++p;
+ ++q;
}
}
}