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

The freeaddrinfo() commits are a replacement for #1918.