fixed an error in garbage collection when the handshake object is undefined or null.

fixed an error in garbage collection when the handshake object is undefined or null.