Comment 9 for bug 1017125

Revision history for this message
In , julien2412 (serval2412-6) wrote :

I'm not sure but :
"erase" invalidates the iterator in the for loop.
Then it breaks so we exit the inner/for loop but we keep on the outer/do loop (since bLinkRemoved =true), then iLink iterator var is recreated and reinitialized with begin.
In brief, yep "erase" invalidates, but then iLink is valid again.
Now perhaps I miss something obvious.

    234 do
    235 {
    236 bLinkRemoved = false;
    237 LinkMap::iterator iLink;
    238 for (iLink=mpLinks->begin(); iLink!=mpLinks->end(); ++iLink)
    239 {
    240 if (iLink->second.mpTargetWindow == pWindow)
    241 {
    242 RemoveUnusedEventListener(iLink->first);
    243 mpLinks->erase(iLink);
    244 bLinkRemoved = true;
    245 break;
    246 }
    247 }
    248 }
    249 while (bLinkRemoved);