Freeing Address Information from Dynamic Allocation
All information returned by the getaddrinfo function pointed to by the res parameter is dynamically allocated, including all addrinfo structures, socket address structures, and canonical host name strings pointed to by addrinfo structures. Memory allocated by a successful call to this function must be released with a subsequent call to freeaddrinfo.
In general you should read up on the function in MSDN - it usually says whether the programmer is responsible for deallocating the buffer, or whether there is a system function (like in the example above) that you call to do the de-allocation.