Fix potential segmentation fault

Call the allocation assertion macro before dereferencing the socket
pointer.
Fix potential memory leak

Delete the socket if the initialization part of the socket creation
fails.
Merge pull request #871 from apyrgio/develop

Fix potential segfault/memleak