Ensure no modifications whilst iterating.

Signed-off-by: Egon Willighagen <egonw@users.sourceforge.net>