From 738310d8cf560c8e246c81d5ecccf4c96e567a58 Mon Sep 17 00:00:00 2001 From: Michael Sawyer Date: Thu, 13 Jul 2000 01:22:38 +0000 Subject: [PATCH] It's probably a bad idea to pre-allocate 64K buffers for each lookup as soon as you read in the batch file. Don't. --- bin/dig/dig.c | 8 ++++---- bin/dig/dighost.c | 15 +++++++++++++-- bin/dig/host.c | 4 ++-- bin/dig/include/dig/dig.h | 6 +++--- bin/dig/nslookup.c | 4 ++-- 5 files changed, 24 insertions(+), 13 deletions(-) diff --git a/bin/dig/dig.c b/bin/dig/dig.c index 1d8943fde5..de80861cfe 100644 --- a/bin/dig/dig.c +++ b/bin/dig/dig.c @@ -15,7 +15,7 @@ * SOFTWARE. */ -/* $Id: dig.c,v 1.61 2000/07/12 17:44:03 mws Exp $ */ +/* $Id: dig.c,v 1.62 2000/07/13 01:22:33 mws Exp $ */ #include #include @@ -1047,7 +1047,7 @@ parse_args(isc_boolean_t is_batchfile, int argc, char **argv) { strcpy(lookup->rttext, "ptr"); strcpy(lookup->rctext, "in"); lookup->namespace[0] = 0; - lookup->sendspace[0] = 0; + lookup->sendspace = NULL; lookup->sendmsg = NULL; lookup->name = NULL; lookup->oname = NULL; @@ -1112,7 +1112,7 @@ parse_args(isc_boolean_t is_batchfile, int argc, char **argv) { lookup->rttext[0] = 0; lookup->rctext[0] = 0; lookup->namespace[0] = 0; - lookup->sendspace[0] = 0; + lookup->sendspace = NULL; lookup->sendmsg = NULL; lookup->name = NULL; lookup->oname = NULL; @@ -1189,7 +1189,7 @@ parse_args(isc_boolean_t is_batchfile, int argc, char **argv) { lookup->pending = ISC_FALSE; lookup->rctext[0] = 0; lookup->namespace[0] = 0; - lookup->sendspace[0] = 0; + lookup->sendspace = NULL; lookup->sendmsg = NULL; lookup->name = NULL; lookup->oname = NULL; diff --git a/bin/dig/dighost.c b/bin/dig/dighost.c index 50b1e6523d..60c5ed006a 100644 --- a/bin/dig/dighost.c +++ b/bin/dig/dighost.c @@ -15,7 +15,7 @@ * SOFTWARE. */ -/* $Id: dighost.c,v 1.78 2000/07/13 00:32:20 mws Exp $ */ +/* $Id: dighost.c,v 1.79 2000/07/13 01:22:34 mws Exp $ */ /* * Notice to programmers: Do not use this code as an example of how to @@ -252,7 +252,7 @@ requeue_lookup(dig_lookup_t *lookold, isc_boolean_t servers) { strncpy(looknew->rttext, lookold-> rttext, 32); strncpy(looknew->rctext, lookold-> rctext, 32); looknew->namespace[0] = 0; - looknew->sendspace[0] = 0; + looknew->sendspace = NULL; looknew->sendmsg = NULL; looknew->name = NULL; looknew->oname = NULL; @@ -645,6 +645,8 @@ clear_query(dig_query_t *query) { if (ISC_LINK_LINKED(&query->lengthbuf, link)) ISC_LIST_DEQUEUE(query->lengthlist, &query->lengthbuf, link); + INSIST(query->recvspace != NULL); + isc_mem_put(mctx, query->recvspace, COMMSIZE); isc_buffer_invalidate(&query->recvbuf); isc_buffer_invalidate(&query->lengthbuf); isc_mem_free(mctx, query); @@ -683,6 +685,8 @@ try_clear_lookup(dig_lookup_t *lookup) { } if (lookup->timer != NULL) isc_timer_detach(&lookup->timer); + INSIST(lookup->sendspace != NULL); + isc_mem_put(mctx, lookup->sendspace, COMMSIZE); ptr = lookup; lookup = ISC_LIST_NEXT(lookup, link); @@ -1129,6 +1133,10 @@ setup_lookup(dig_lookup_t *lookup) { lookup->querysig = NULL; } + lookup->sendspace = isc_mem_get(mctx, COMMSIZE); + if (lookup->sendspace == NULL) + fatal("memory allocation failure"); + debug("starting to render the message"); isc_buffer_init(&lookup->sendbuf, lookup->sendspace, COMMSIZE); result = dns_message_renderbegin(lookup->sendmsg, &lookup->sendbuf); @@ -1172,6 +1180,9 @@ setup_lookup(dig_lookup_t *lookup) { ISC_LIST_INIT(query->recvlist); ISC_LIST_INIT(query->lengthlist); query->sock = NULL; + query->recvspace = isc_mem_get(mctx, COMMSIZE); + if (query->recvspace == NULL) + fatal("memory allocation failure"); isc_buffer_init(&query->recvbuf, query->recvspace, COMMSIZE); isc_buffer_init(&query->lengthbuf, query->lengthspace, 2); diff --git a/bin/dig/host.c b/bin/dig/host.c index ca67b84600..d73a1f5069 100644 --- a/bin/dig/host.c +++ b/bin/dig/host.c @@ -15,7 +15,7 @@ * SOFTWARE. */ -/* $Id: host.c,v 1.37 2000/07/10 18:02:29 bwelling Exp $ */ +/* $Id: host.c,v 1.38 2000/07/13 01:22:35 mws Exp $ */ #include #include @@ -661,7 +661,7 @@ parse_args(isc_boolean_t is_batchfile, int argc, char **argv) { strncpy(lookup->rttext, querytype, 32); strncpy(lookup->rctext, queryclass, 32); lookup->namespace[0] = 0; - lookup->sendspace[0] = 0; + lookup->sendspace = NULL; lookup->sendmsg = NULL; lookup->name = NULL; lookup->oname = NULL; diff --git a/bin/dig/include/dig/dig.h b/bin/dig/include/dig/dig.h index 66d2c3f431..120f7c3201 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.30 2000/07/10 18:02:31 bwelling Exp $ */ +/* $Id: dig.h,v 1.31 2000/07/13 01:22:38 mws Exp $ */ #ifndef DIG_H #define DIG_H @@ -99,7 +99,7 @@ struct dig_lookup { isc_buffer_t namebuf; isc_buffer_t onamebuf; isc_buffer_t sendbuf; - char sendspace[COMMSIZE]; + char *sendspace; dns_name_t *name; isc_timer_t *timer; isc_interval_t interval; @@ -139,7 +139,7 @@ struct dig_query { isc_buffer_t recvbuf, lengthbuf, slbuf; - char recvspace[COMMSIZE], + char *recvspace, lengthspace[4], slspace[4]; isc_socket_t *sock; diff --git a/bin/dig/nslookup.c b/bin/dig/nslookup.c index 6de37deabf..5f032a4923 100644 --- a/bin/dig/nslookup.c +++ b/bin/dig/nslookup.c @@ -15,7 +15,7 @@ * SOFTWARE. */ -/* $Id: nslookup.c,v 1.23 2000/07/05 23:28:30 mws Exp $ */ +/* $Id: nslookup.c,v 1.24 2000/07/13 01:22:36 mws Exp $ */ #include @@ -651,7 +651,7 @@ addlookup(char *opt) { strncpy (lookup->rttext, deftype, MXNAME); strncpy (lookup->rctext, defclass, MXNAME); lookup->namespace[0]=0; - lookup->sendspace[0]=0; + lookup->sendspace = NULL; lookup->sendmsg=NULL; lookup->name=NULL; lookup->oname=NULL;