[zeromq-dev] [PATCH] more iterator invalidation patches

Martin Sustrik sustrik at 250bpm.com
Sun May 8 07:25:50 CEST 2011


Hi Jon,

> the iterators are not handled correctly when using erase on the
> container in two places on
> the inpipes and outpipes collections respectively.

 > -            inpipes.erase (it);
 > +            it = inpipes.erase (it);

Unfortunately, the vector::erase function is defined as void in some STL 
implementations.

 > -            outpipes.erase (it);
 > +            outpipes.erase (it++);

This doesn't solve the problem. The iterator is used *after* erasing 
both in the original code and your patch.

The real solution would be either to use array indices instead of 
iterators or STL algorithms such as remove_if.

Martin




More information about the zeromq-dev mailing list