return -1;
}
+ addrinfo *base_ai = ai;
+
// Connect to everything in turn until we have a socket.
while (ai && !should_stop) {
int sock = socket(ai->ai_family, SOCK_STREAM, IPPROTO_TCP);
} while (err == -1 && errno == EINTR);
if (err != -1) {
- freeaddrinfo(ai);
+ freeaddrinfo(base_ai);
return sock;
}
// Give the last one as error.
log(WARNING, "[%s] Connect to '%s' failed (%s)",
stream_id.c_str(), host.c_str(), strerror(errno));
- freeaddrinfo(ai);
+ freeaddrinfo(base_ai);
return -1;
}