Fix use of invalidated iterator
Merge remote-tracking branch 'upstream/master' into resource-refactor