Using invalidated vector iterator is at best a UB and could crash depending on STL implementation. Fixing via minimal changes to preserve the existing code style. Coverity warning 1454828 (scan.coverity.com) Differential Revision: https://reviews.llvm.org/D130312