Fix dangling pointer bug

If there is more than one STUN server and the name is
shorter than std::string small string optimization size.

(cherry picked from commit b88a52c206)
This commit is contained in:
Fletcher Dunn
2026-05-22 22:22:02 -07:00
parent fb89e13c67
commit d038acf945
@@ -134,8 +134,11 @@ void CSteamNetworkConnectionP2P::CheckInitICE()
server.append( pszAddress );
vecStunServers.push_back( std::move( server ) );
vecStunServersPsz.push_back( vecStunServers.rbegin()->c_str() );
}
// Build the pointer array after vecStunServers is fully populated;
// doing it inside the loop would produce dangling pointers on reallocation.
for ( const std::string &s: vecStunServers )
vecStunServersPsz.push_back( s.c_str() );
}
if ( vecStunServers.empty() )
SpewWarningGroup( LogLevel_P2PRendezvous(), "[%s] Reflexive candidates enabled by P2P_Transport_ICE_Enable, but P2P_STUN_ServerList is empty\n", GetDescription() );