Fix a memory trample and some bad freeaddrinfo() calls.

The freeaddrinfo() commits are a replacement for #1918.
``if (response != NULL)`` is unnecessary. ``response`` is guaranteed to be non-NULL because of ``ap = response; while (ap != NULL ...`` on line 218.