Broken removeDestinationFromList()

"Martin Mainka" <[email protected]> Fri, 19 Oct 2007 19:11:13 +0200
Newsgroups gmane.comp.gnu.ccrtp.devel
Message-ID <000301c81273$0d8afa50$0400a8c0@mainka4>
Hi,
The removeDestinationFromList() function is broken (Increment on an
undefined iterator) after destList.erase(i).
I send a correction that does increment before iterator i becomes invalid.
With this the problem is solved.



bool
DestinationListHandler::removeDestinationFromList(const InetAddress& ia,
						  tpport_t dataPort,
						  tpport_t controlPort)
{
	bool result = false;
	writeLockDestinationList();
	TransportAddress* tmp;

	std::list<TransportAddress*>::iterator i;

	for ( i = destList.begin(); destList.end() != i && !result;)
<-------------
	{
		tmp = *i;
		if ( ia == tmp->getNetworkAddress() &&
		     dataPort == tmp->getDataTransportPort() &&
		     controlPort == tmp->getControlTransportPort() ) 
		{
			// matches. -> remove it.
			result = true;
			destList.erase(i++);          <-------------
			delete tmp;
		}
		else
		{
			i++;     <-------------
		}
	}
	unlockDestinationList();
	return result;
}


With best regards

Martin Mainka