Check socket pointer before dereferencing it

A socket is created with the `new` construct, but the result of the
allocation is not checked before dereferencing the socket pointer.
Fix potential memory leak

An allocated socket is not deleted if subsequent initialization tasks
fail.