Fix blatant memory trample.

(cherry picked from commit f242cb65ac9f84f6a939371b88f62d092c50a972)
Fix for uninitialized pointer free in SocketConnect().

As pointed out by @worr in #1918, failure of getaddrinfo() may leave
response2 unset, in which case calling freeaddrinfo() on it is apt to
crash.  None the less, nothing guarantees that failing getaddrinfo()
won't set the response list (e.g. when OOM prevents it allocating
space for further entries).  So initialise it to NULL.

Also move the declaration closer to its use.

(cherry picked from commit 87449edc027d0cc9f408c157e3b038c4dd96a627)
Protect against freeaddrinfo(NULL);

Apparently some implementations don't handle this gracefully.
/me bangs head on wall, but is glad I googled.

(cherry picked from commit a79088afbc0f065eb06a6c3116d8272f4a74207c)
Fix another addrinfo corner case in SocketConnect().

The initial call to getaddrinfo() is subject to the same concerns as
the secondary one, as noticed by @jimis in code review.

(cherry picked from commit c7810dd05782aeee46d930cbf7ee4b94cf6d7f7c)