Skip to content

Commit

Permalink
SERVER-5081 do not delete iterator until after it's incremented
Browse files Browse the repository at this point in the history
Avoids memory reads of freed memory.
  • Loading branch information
milkie authored and erh committed Mar 5, 2012
1 parent d13fb74 commit abb6284
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions db/repl/rs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,17 +100,20 @@ namespace mongo {
lock lk(this);

Member *max = 0;

for (set<unsigned>::iterator it = _electableSet.begin(); it != _electableSet.end(); it++) {
set<unsigned>::iterator it = _electableSet.begin();
while ( it != _electableSet.end() ) {
const Member *temp = findById(*it);
if (!temp) {
log() << "couldn't find member: " << *it << endl;
_electableSet.erase(*it);
set<unsigned>::iterator it_delete = it;
it++;
_electableSet.erase(it_delete);
continue;
}
if (!max || max->config().priority < temp->config().priority) {
max = (Member*)temp;
}
it++;
}

return max;
Expand Down

0 comments on commit abb6284

Please sign in to comment.