]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
fix nslookup memory leak introduced by earlier pullup of
authorAndreas Gustafsson <source@isc.org>
Mon, 7 Aug 2000 23:50:17 +0000 (23:50 +0000)
committerAndreas Gustafsson <source@isc.org>
Mon, 7 Aug 2000 23:50:17 +0000 (23:50 +0000)
dig 64k memory allocation fix not changing all instances of duplicated
lookup least cleanup code; pull up support for '-' option

bin/dig/dighost.c
bin/dig/include/dig/dig.h
bin/dig/nslookup.c

index b7af49cfb2b68fa7949665e83c792ebf19f160ff..947ecc7b8f844b720743a82ab2838561face691d 100644 (file)
@@ -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) {
        /*
index 270abba9b6ba3752d7241c85c8b79a3fd51ec169..fa85a9c7c6cfe4044e877d4a713a39d0b612d63b 100644 (file)
@@ -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.
index 34f9517d3fd0c925b32d92148432a2bdd4b9125c..b6e7358da43c65ada347c92c8421835ed59dc7cc 100644 (file)
@@ -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 <config.h>
 
@@ -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;