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

The freeaddrinfo() commits are a replacement for #1918.
But it does no harm, of course!