I have a function in which I call getaddrinfo() to get an sockaddr* which targets memory is allocated by the system. As many may know, you need to call
getaddrinfo()
sockaddr*
You could wrap the addrinfo in a class that calls getaddrinfo in the constructor and freeaddrinfo in its destructor.
getaddrinfo
freeaddrinfo
That way it will always be freed, whether there is an exception thrown or not.