Fix crash when connecting via TLS the first time