Connection::RemoveSubscriber() correctly sets the vector iterator to the return value of std::vector::erase() when an item is removed but the for loop always advances the iterator. The value returned from std::vector::erase() is the next valid iterator or the value of std::vector::end() if the deleted item is the last one. If the subscriber is in the vector twice with no other elements in between the second instance of the subscriber will be skipped. If the subscriber is the last one in the vector the loop will attempt to iterate past the end of the vector. This can cause a crash depending on the platform and memory contents. At the least it is undefined behavior. I am submitting a patch that resolves the issue by only advancing the iterator when an element is not erased.
Reference for behavior of std::vector::erase(): http://www.cplusplus.com/reference/vector/vector/erase/
Anonymous
Thanks.