From: Andreas Gustafsson Date: Mon, 7 Aug 2000 23:50:17 +0000 (+0000) Subject: fix nslookup memory leak introduced by earlier pullup of X-Git-Tag: v9.0.0rc2~9 X-Git-Url: http://git.ipfire.org/gitweb/?a=commitdiff_plain;h=460947be44a6e8b8c60ec4a145ec7add4c51ebaf;p=thirdparty%2Fbind9.git fix nslookup memory leak introduced by earlier pullup of dig 64k memory allocation fix not changing all instances of duplicated lookup least cleanup code; pull up support for '-' option --- diff --git a/bin/dig/dighost.c b/bin/dig/dighost.c index b7af49cfb2b..947ecc7b8f8 100644 --- a/bin/dig/dighost.c +++ b/bin/dig/dighost.c @@ -15,7 +15,7 @@ * SOFTWARE. */ -/* $Id: dighost.c,v 1.58.2.8 2000/07/26 22:28:31 gson Exp $ */ +/* $Id: dighost.c,v 1.58.2.9 2000/08/07 23:50:13 gson Exp $ */ /* * Notice to programmers: Do not use this code as an example of how to @@ -184,6 +184,26 @@ check_result(isc_result_t result, const char *msg) { } } +/* + * Create a server structure, which is part of the lookup structure. + * This is little more than a linked list of servers to query in hopes + * of finding the answer the user is looking for + */ +dig_server_t * +make_server(const char *servname) { + dig_server_t *srv; + + REQUIRE(servname != NULL); + + debug("make_server(%s)",servname); + srv = isc_mem_allocate(mctx, sizeof(struct dig_server)); + if (srv == NULL) + fatal("Memory allocation failure in %s:%d", + __FILE__, __LINE__); + strncpy(srv->servername, servname, MXNAME); + return (srv); +} + isc_boolean_t isclass(char *text) { /* diff --git a/bin/dig/include/dig/dig.h b/bin/dig/include/dig/dig.h index 270abba9b6b..fa85a9c7c6c 100644 --- a/bin/dig/include/dig/dig.h +++ b/bin/dig/include/dig/dig.h @@ -15,7 +15,7 @@ * SOFTWARE. */ -/* $Id: dig.h,v 1.25.2.3 2000/07/17 19:40:55 gson Exp $ */ +/* $Id: dig.h,v 1.25.2.4 2000/08/07 23:50:17 gson Exp $ */ #ifndef DIG_H #define DIG_H @@ -209,6 +209,8 @@ free_lists(void); dig_lookup_t * requeue_lookup(dig_lookup_t *lookold, isc_boolean_t servers); +dig_server_t * +make_server(const char *servname); /* * Routines needed in dig.c and host.c. diff --git a/bin/dig/nslookup.c b/bin/dig/nslookup.c index 34f9517d3fd..b6e7358da43 100644 --- a/bin/dig/nslookup.c +++ b/bin/dig/nslookup.c @@ -15,7 +15,7 @@ * SOFTWARE. */ -/* $Id: nslookup.c,v 1.20.2.2 2000/07/17 19:40:54 gson Exp $ */ +/* $Id: nslookup.c,v 1.20.2.3 2000/08/07 23:50:16 gson Exp $ */ #include @@ -59,6 +59,7 @@ extern int lookup_counter; extern char fixeddomain[MXNAME]; extern int exitcode; extern isc_taskmgr_t *taskmgr; +extern isc_mempool_t *commctx; extern char *progname; isc_boolean_t short_form = ISC_TRUE, printcmd = ISC_TRUE, @@ -585,6 +586,7 @@ show_settings(isc_boolean_t full) { static void setoption(char *opt) { + dig_server_t *srv; if (strncasecmp(opt,"all",4) == 0) { show_settings(ISC_TRUE); @@ -635,10 +637,14 @@ setoption(char *opt) { debugging = ISC_FALSE; } else if (strncasecmp(opt, "sil",3) == 0) { deprecation_msg = ISC_FALSE; + } else { + srv = make_server(opt); + debug("server is %s", srv->servername); + ISC_LIST_APPEND(server_list, srv, link); } } -static void +static dig_lookup_t* addlookup(char *opt) { dig_lookup_t *lookup; @@ -687,6 +693,7 @@ addlookup(char *opt) { lookup->origin = NULL; ISC_LIST_INIT(lookup->my_server_list); debug("looking up %s", lookup->textname); + return (lookup); } static void @@ -751,6 +758,7 @@ get_next_command(void) { static void parse_args(int argc, char **argv) { dig_lookup_t *lookup = NULL; + isc_boolean_t have_lookup = ISC_FALSE; for (argc--, argv++; argc > 0; argc--, argv++) { debug ("main parsing %s", argv[0]); @@ -762,10 +770,13 @@ parse_args(int argc, char **argv) { } if (argv[0][1] != 0) setoption(&argv[0][1]); + else + have_lookup = ISC_TRUE; } else { - if (lookup == NULL) { + if (!have_lookup) { + have_lookup = ISC_TRUE; in_use = ISC_TRUE; - addlookup(argv[0]); + lookup = addlookup(argv[0]); } else setsrv(argv[0]); @@ -795,6 +806,8 @@ flush_lookup_list(void) { if (ISC_LINK_LINKED(&q->lengthbuf, link)) ISC_LIST_DEQUEUE(q->lengthlist, &q->lengthbuf, link); + INSIST(q->recvspace != NULL); + isc_mempool_put(commctx, q->recvspace); isc_buffer_invalidate(&q->recvbuf); isc_buffer_invalidate(&q->lengthbuf); qp = q; @@ -814,6 +827,8 @@ flush_lookup_list(void) { } if (l->sendmsg != NULL) dns_message_destroy(&l->sendmsg); + if (l->sendspace != NULL) + isc_mempool_put(commctx, l->sendspace); if (l->timer != NULL) isc_timer_detach(&l->timer); lp = l;