I would keep the freeaddrinfo before the goto error (same for the second that you removed below), conditionned by "if (rc == 0)", because I think in that case something could have been partially allocated by getaddrinfo().