Fix several bogus bugs

-Some address resolving related structures were not freed after use.
 -Some error messages were not printed out correctly.

Approved by: jkh
This commit is contained in:
Yoshinobu Inoue 2000-02-12 15:03:05 +00:00
parent eb06360f04
commit 2bd54ee847
3 changed files with 10 additions and 5 deletions

View File

@ -98,7 +98,7 @@ url_get(origline, proxyenv)
const char *proxyenv;
{
struct addrinfo hints;
struct addrinfo *res;
struct addrinfo *res0, *res;
char nameinfo[2 * INET6_ADDRSTRLEN + 1];
int i, out, isftpurl;
char *port;
@ -207,9 +207,10 @@ url_get(origline, proxyenv)
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
error = getaddrinfo(host, port, &hints, &res);
res0 = res;
if (error) {
warnx("%s: %s", host, gai_strerror(error));
if (error = EAI_SYSTEM)
if (error == EAI_SYSTEM)
warnx("%s: %s", host, strerror(errno));
goto cleanup_url_get;
}
@ -238,11 +239,13 @@ url_get(origline, proxyenv)
res = res->ai_next;
if (res)
continue;
warn("Can't connect to %s", host);
goto cleanup_url_get;
}
break;
}
freeaddrinfo(res0);
/*
* Construct and send the request. We're expecting a return
@ -394,6 +397,8 @@ cleanup_url_get:
if (proxy)
free(proxy);
free(line);
if (res0 != NULL)
freeaddrinfo(res0);
return (-1);
}

View File

@ -166,6 +166,7 @@ hookup(host, port)
goto bad;
}
memcpy(&hisctladdr, res->ai_addr, res->ai_addrlen);
freeaddrinfo(res0);
len = sizeof(myctladdr);
if (getsockname(s, (struct sockaddr *)&myctladdr, &len) < 0) {
warn("getsockname");

View File

@ -232,10 +232,9 @@ main(argc, argv)
hints.ai_socktype = SOCK_STREAM;
error = getaddrinfo(src_addr, NULL, &hints, &res);
if (error) {
fprintf(stderr, "%s: %s", src_addr,
gai_strerror(error));
warnx("%s: %s", src_addr, gai_strerror(error));
if (error == EAI_SYSTEM)
errx(1, "%s", strerror(errno));
warnx("%s", strerror(errno));
exit(1);
}
memcpy(&bindto, res->ai_addr, res->ai_addrlen);