summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjca <jca@openbsd.org>2018-06-19 11:28:11 +0000
committerjca <jca@openbsd.org>2018-06-19 11:28:11 +0000
commitd87452526914ca75945d461881c729bcd482a3f3 (patch)
tree5fe56f1c80f1b67f11bd59f4ab92177f512c138f
parentSend the calling thread id, effective uid and gid, and umask to the (diff)
downloadwireguard-openbsd-d87452526914ca75945d461881c729bcd482a3f3.tar.xz
wireguard-openbsd-d87452526914ca75945d461881c729bcd482a3f3.zip
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@
-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);