Avoid using an invalidated iterator
Merge pull request #5621 from chinhodado/patch-2

Avoid using an invalidated iterator