BUG-152 - DestroySocket can leave a freed CServerSocket pointer in the connectionattempts map¶
Summary¶
CServerConnect tracks in-flight connection attempts in the
connectionattempts map (key: timestamp, value: CServerSocket*). Several
socket-destroy paths reach CServerConnect::DestroySocket without first
removing the socket from that map: CServerSocket::OnClose while in
CS_WAITFORLOGIN, and the early-out branch in ConnectionFailed. After
DestroySocket deletes the socket, the map still holds the now-freed
pointer, and the next walk of connectionattempts (in AwaitingTestFromIP
or AwaitingConnectionToServer) dereferences freed memory and crashes.
Fix¶
In DestroySocket, before deleting the socket, scan connectionattempts and
remove any entry whose value equals the socket being destroyed. This makes the
map self-consistent regardless of which destroy path was taken, so it can never
retain a dangling pointer.
File: srchybrid/ServerConnect.cpp (CServerConnect::DestroySocket).