Prevent dereferencing NULL pointer in TcpSocket.disconnect