diff --git a/libretroshare/src/turtle/p3turtle.cc b/libretroshare/src/turtle/p3turtle.cc index d5d1b8988..2001a7617 100644 --- a/libretroshare/src/turtle/p3turtle.cc +++ b/libretroshare/src/turtle/p3turtle.cc @@ -367,29 +367,40 @@ void p3turtle::locked_closeTunnel(TurtleTunnelId tid) std::cerr << " Associated file source." << std::endl ; #endif _ft_controller->removeFileSource(hash,vpid) ; - _virtual_peers.erase(_virtual_peers.find(vpid)) ; - std::vector& tunnels(_incoming_file_hashes[hash].tunnels) ; - - // Remove tunnel id from it's corresponding hash. For security we - // go through the whole tab, although the tunnel id should only be listed once - // in this tab. + // Let's be cautious. Normally we should never be here without consistent information, + // but still, this happens, rarely. // - for(unsigned int i=0;i::iterator it(_incoming_file_hashes.find(hash)) ; + + if(it != _incoming_file_hashes.end()) + { + std::vector& tunnels(it->second.tunnels) ; + + // Remove tunnel id from it's corresponding hash. For security we + // go through the whole tab, although the tunnel id should only be listed once + // in this tab. + // + for(unsigned int i=0;isecond.local_dst == mConnMgr->getOwnId()) // This is a ending tunnel. We also remove the virtual peer id { #ifdef P3TURTLE_DEBUG std::cerr << " Tunnel is a ending point. Also removing associated outgoing hash." ; #endif - _outgoing_file_hashes.erase(_outgoing_file_hashes.find(it->second.hash)) ; + if(_outgoing_file_hashes.find(it->second.hash) != _outgoing_file_hashes.end()) + _outgoing_file_hashes.erase(_outgoing_file_hashes.find(it->second.hash)) ; } _local_tunnels.erase(it) ;