Skip to content

Commit b88a52c

Browse files
committed
Fix dangling pointer bug
If there is more than one STUN server and the name is shorter than std::string small string optimization size.
1 parent 951a3a9 commit b88a52c

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

src/steamnetworkingsockets/clientlib/steamnetworkingsockets_p2p_ice.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,11 @@ void CSteamNetworkConnectionP2P::CheckInitICE()
134134
server.append( pszAddress );
135135

136136
vecStunServers.push_back( std::move( server ) );
137-
vecStunServersPsz.push_back( vecStunServers.rbegin()->c_str() );
138137
}
138+
// Build the pointer array after vecStunServers is fully populated;
139+
// doing it inside the loop would produce dangling pointers on reallocation.
140+
for ( const std::string &s: vecStunServers )
141+
vecStunServersPsz.push_back( s.c_str() );
139142
}
140143
if ( vecStunServers.empty() )
141144
SpewWarningGroup( LogLevel_P2PRendezvous(), "[%s] Reflexive candidates enabled by P2P_Transport_ICE_Enable, but P2P_STUN_ServerList is empty\n", GetDescription() );

0 commit comments

Comments
 (0)