Fix potential segfault/memleak

This set of patches fixes a potential segfault/memleak in file socket_base.cpp. The conditions under which they are triggered are easy to see:
* Allocation assertion after a dereference.
* No deletion of allocated object in case of an error.

The proposed patch should counter these bugs.