Fix crash when telnet or other protocols close.

http://code.google.com/p/flightgear-bugs/issues/detail?id=1144
This commit is contained in:
James Turner
2013-06-26 21:50:27 +01:00
parent c458c13af7
commit 6edb0f66d5
+5 -3
View File
@@ -273,7 +273,6 @@ NetChannelPoller::poll(unsigned int timeout)
int nreads = 0 ; int nreads = 0 ;
int nwrites = 0 ; int nwrites = 0 ;
int nopen = 0 ; int nopen = 0 ;
NetChannel* ch;
ChannelList::iterator it = channels.begin(); ChannelList::iterator it = channels.begin();
while( it != channels.end() ) while( it != channels.end() )
@@ -281,6 +280,9 @@ NetChannelPoller::poll(unsigned int timeout)
NetChannel* ch = *it; NetChannel* ch = *it;
if ( ch -> should_delete ) if ( ch -> should_delete )
{ {
// avoid the channel trying to remove itself from us, or we get
// bug http://code.google.com/p/flightgear-bugs/issues/detail?id=1144
ch->poller = NULL;
delete ch; delete ch;
it = channels.erase(it); it = channels.erase(it);
continue; continue;
@@ -320,14 +322,14 @@ NetChannelPoller::poll(unsigned int timeout)
for ( int i=0; reads[i]; i++ ) for ( int i=0; reads[i]; i++ )
{ {
ch = (NetChannel*)reads[i]; NetChannel* ch = (NetChannel*)reads[i];
if ( ! ch -> closed ) if ( ! ch -> closed )
ch -> handleReadEvent(); ch -> handleReadEvent();
} }
for ( int i=0; writes[i]; i++ ) for ( int i=0; writes[i]; i++ )
{ {
ch = (NetChannel*)writes[i]; NetChannel* ch = (NetChannel*)writes[i];
if ( ! ch -> closed ) if ( ! ch -> closed )
ch -> handleWriteEvent(); ch -> handleWriteEvent();
} }