Hello,
I have one question regarding the example of getaddrinfo() (getaddrinfo(3)).
The example is something like:
My question is: if socket() always fails (e.g., errno == EMFILE) or connect() always fails, the application would call:
without calling:
Though it is not that bad because the memory will be freed anyway when the program exits, wouldn't it be better to call freeaddrinfo(res0); before calling err()?
Thank you.
I have one question regarding the example of getaddrinfo() (getaddrinfo(3)).
The example is something like:
Code:
s = -1;
for (res = res0; res; res = res->ai_next) {
s = socket(res->ai_family, res->ai_socktype,
res->ai_protocol);
if (s < 0) {
cause = "socket";
continue;
}
if (connect(s, res->ai_addr, res->ai_addrlen) < 0) {
cause = "connect";
close(s);
s = -1;
continue;
}
break; /* okay we got one */
}
if (s < 0) {
err(1, "%s", cause);
/*NOTREACHED*/
}
freeaddrinfo(res0);
My question is: if socket() always fails (e.g., errno == EMFILE) or connect() always fails, the application would call:
Code:
err(1, "%s", cause);
without calling:
Code:
freeaddrinfo(res0);
Though it is not that bad because the memory will be freed anyway when the program exits, wouldn't it be better to call freeaddrinfo(res0); before calling err()?
Thank you.