summaryrefslogtreecommitdiff
path: root/usr.bin/whois
diff options
context:
space:
mode:
authorJeremie Courreges-Anglas <jca@cvs.openbsd.org>2018-06-19 11:28:12 +0000
committerJeremie Courreges-Anglas <jca@cvs.openbsd.org>2018-06-19 11:28:12 +0000
commit9461db4e963d9472a1c6997b4322f2420e8ec301 (patch)
tree7634295568efd5e60994b01044bf0448cce305ac /usr.bin/whois
parent57436230755cc8f123e77d7f7ac1a438cba5e871 (diff)
Plug getaddrinfo(3) memory leak
choose_server() calls getaddrinfo(3) but never frees the result. Minimal fix that relies on getaddrinfo(3) only updating the "res" pointer if the call was successful. While here, call freeaddrinfo(3) earlier in whois(), less code and less overall memory used since whois() can recurse. ok millert@ tb@ benno@
Diffstat (limited to 'usr.bin/whois')
-rw-r--r--usr.bin/whois/whois.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/usr.bin/whois/whois.c b/usr.bin/whois/whois.c
index fe1fa224a66..13df7a7b9f1 100644
--- a/usr.bin/whois/whois.c
+++ b/usr.bin/whois/whois.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: whois.c,v 1.57 2018/06/17 15:34:54 florian Exp $ */
+/* $OpenBSD: whois.c,v 1.58 2018/06/19 11:28:11 jca Exp $ */
/*
* Copyright (c) 1980, 1993
@@ -196,13 +196,13 @@ whois(const char *query, const char *server, const char *port, int flags)
}
break; /*okay*/
}
+ freeaddrinfo(res);
if (s == -1) {
if (reason) {
errno = error;
warn("%s: %s", server, reason);
} else
warn("unknown error in connection attempt");
- freeaddrinfo(res);
return (1);
}
@@ -269,7 +269,7 @@ whois(const char *query, const char *server, const char *port, int flags)
error = whois(query, nhost, port, 0);
free(nhost);
}
- freeaddrinfo(res);
+
return (error);
}
@@ -287,7 +287,7 @@ choose_server(const char *name, const char *country, char **tofree)
char *server;
const char *qhead;
char *ep;
- struct addrinfo hints, *res;
+ struct addrinfo hints, *res = NULL;
memset(&hints, 0, sizeof(hints));
hints.ai_flags = 0;
@@ -339,6 +339,8 @@ choose_server(const char *name, const char *country, char **tofree)
if (asprintf(&server, "%s%s", qhead, QNICHOST_TAIL) == -1)
err(1, NULL);
}
+ if (res != NULL)
+ freeaddrinfo(res);
*tofree = server;
return (server);