Fix invalid use of iterator after erase and lock corruption.

* The call to _TeamDied() causes the team that the iterator points to
  be removed from the map. Therefore the iterator becomes invalid and
  may not be accessed anymore (including incrementing it). As we've had
  to unlock, anything might have happened to to map, so take the safe
  route and just start over.
* For each dead team that was found the AppManager was unlocked, but
  there were no balancing lock calls, therefore causing the lock count
  to get corrupted.
This commit is contained in:
Michael Lotz
2011-12-10 21:23:35 +01:00
parent 5585262bb1
commit bcc4a523b6
+8 -3
View File
@@ -189,7 +189,7 @@ AppManager::_BigBrotherEntry(void* self)
void void
AppManager::_BigBrother() AppManager::_BigBrother()
{ {
status_t status; status_t status = B_TIMED_OUT;
BMessage ping('PING'); BMessage ping('PING');
BMessage reply; BMessage reply;
@@ -197,6 +197,7 @@ AppManager::_BigBrother()
if (!Lock()) if (!Lock())
break; break;
bool startOver = false;
AppMap::iterator iterator = fMap.begin(); AppMap::iterator iterator = fMap.begin();
for (; iterator != fMap.end(); iterator++) { for (; iterator != fMap.end(); iterator++) {
reply.what = 0; reply.what = 0;
@@ -207,11 +208,15 @@ AppManager::_BigBrother()
Unlock(); Unlock();
_TeamDied(team); _TeamDied(team);
continue; startOver = true;
break;
} }
} }
Unlock();
if (startOver)
continue;
Unlock();
status = acquire_sem_etc(fQuit, 1, B_RELATIVE_TIMEOUT, 2000000); status = acquire_sem_etc(fQuit, 1, B_RELATIVE_TIMEOUT, 2000000);
} while (status == B_TIMED_OUT || status == B_INTERRUPTED); } while (status == B_TIMED_OUT || status == B_INTERRUPTED);
} }