Fixed a crash when closing socket with nil delegate