Handle invalid handshake data properly in the core

Clients sending invalid handshake data could make the core crash
due to an unchecked pointer. This commit fixes this issue by having
the core close the socket if a peer could not be created.

Thanks to Bas Pape (Tucos) for finding this one!