diff --git a/src/kits/app/Handler.cpp b/src/kits/app/Handler.cpp index 9da37c39dc..a5947b1b69 100644 --- a/src/kits/app/Handler.cpp +++ b/src/kits/app/Handler.cpp @@ -682,14 +682,15 @@ ObserverList::_ValidateHandlers(uint32 what) vector& handlers = fHandlerMap[what]; vector::iterator iterator = handlers.begin(); - for (; iterator != handlers.end(); iterator++) { + while (iterator != handlers.end()) { BMessenger target(*iterator); - if (!target.IsValid()) + if (!target.IsValid()) { + iterator++; continue; + } - handlers.erase(iterator); - iterator--; Add(target, what); + handlers.erase(iterator); } } @@ -704,13 +705,14 @@ ObserverList::_SendNotices(uint32 what, BMessage* message) vector& messengers = fMessengerMap[what]; vector::iterator iterator = messengers.begin(); - for (; iterator != messengers.end(); iterator++) { + while (iterator != messengers.end()) { if (!(*iterator).IsValid()) { messengers.erase(iterator); continue; } (*iterator).SendMessage(message); + iterator++; } }