Hi,
here are two tweaks for whois.c:
- in whois() call freeaddrinfo(3) asap, there is no reason to keep the
results around for longer than necessary. whois() is recursive so
this should reduce the amount of memory used when following redirects.
- choose_server() doesn't attempt to free the getaddrinfo(3) results,
I think the least intrusive way is to rely on the fact that
getaddrinfo(3) only updates the "res" pointer on a successful call.
Tested with ./obj/whois nic.africa
Comments, ok?
Index: whois.c
===================================================================
RCS file: /d/cvs/src/usr.bin/whois/whois.c,v
retrieving revision 1.57
diff -u -p -p -u -r1.57 whois.c
--- whois.c 17 Jun 2018 15:34:54 -0000 1.57
+++ whois.c 18 Jun 2018 18:05:17 -0000
@@ -196,13 +196,13 @@ whois(const char *query, const char *ser
}
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 *ser
error = whois(query, nhost, port, 0);
free(nhost);
}
- freeaddrinfo(res);
+
return (error);
}
@@ -287,7 +287,7 @@ choose_server(const char *name, const ch
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 ch
if (asprintf(&server, "%s%s", qhead, QNICHOST_TAIL) == -1)
err(1, NULL);
}
+ if (res != NULL)
+ freeaddrinfo(res);
*tofree = server;
return (server);
--
jca | PGP : 0x1524E7EE / 5135 92C1 AD36 5293 2BDF DDCC 0DFA 74AE 1524 E7EE