]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
reviewed: marka
authorMark Andrews <marka@isc.org>
Tue, 6 Aug 2002 04:23:20 +0000 (04:23 +0000)
committerMark Andrews <marka@isc.org>
Tue, 6 Aug 2002 04:23:20 +0000 (04:23 +0000)
1354.   [bug]           nsupdate was extremely wasteful of memory.

CHANGES
bin/nsupdate/nsupdate.c

diff --git a/CHANGES b/CHANGES
index 7fb772747f28f93ff04d3739f4d92b520c0b10bd..f1b47a3a6ed1a002bee704efc18b4a69426bc902 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,5 @@
+1354.  [bug]           nsupdate was extremely wasteful of memory.
+
 1355.  [tuning]        Reduce the number of events / quantum for zone tasks.
 
 1354.  [doc]           lwres man pages had illegal nroff.
index 14abf69bd9e47054d66a2a613bbe6d92bcc324f9..76a505a836709d8917b2edf9fdf18fc621e17b52 100644 (file)
@@ -15,7 +15,7 @@
  * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: nsupdate.c,v 1.103.2.10 2002/07/11 03:51:27 marka Exp $ */
+/* $Id: nsupdate.c,v 1.103.2.11 2002/08/06 04:23:20 marka Exp $ */
 
 #include <config.h>
 
@@ -81,8 +81,7 @@ extern int h_errno;
 #endif
 
 #define MAXCMD (4 * 1024)
-#define INITDATA (32 * 1024)
-#define MAXDATA (64 * 1024)
+#define MAXWIRE (64 * 1024)
 #define NAMEBUF 512
 #define WORDLEN 512
 #define PACKETSIZE ((64 * 1024) - 1)
@@ -731,12 +730,12 @@ parse_rdata(char **cmdlinep, dns_rdataclass_t rdataclass,
            dns_rdata_t *rdata)
 {
        char *cmdline = *cmdlinep;
-       isc_buffer_t source, *buf = NULL;
+       isc_buffer_t source, *buf = NULL, *newbuf = NULL;
+       isc_region_t r;
        isc_lex_t *lex = NULL;
        dns_rdatacallbacks_t callbacks;
        isc_result_t result;
        dns_name_t *rn;
-       int bufsz = INITDATA;
 
        while (*cmdline != 0 && isspace((unsigned char)*cmdline))
                cmdline++;
@@ -747,33 +746,31 @@ parse_rdata(char **cmdlinep, dns_rdataclass_t rdataclass,
                        rn = userzone;
                else
                        rn = origin;
-               do {
-                       result = isc_lex_create(mctx, strlen(cmdline), &lex);
-                       check_result(result, "isc_lex_create");
-                       isc_buffer_init(&source, cmdline, strlen(cmdline));
-                       isc_buffer_add(&source, strlen(cmdline));
-                       result = isc_lex_openbuffer(lex, &source);
-                       check_result(result, "isc_lex_openbuffer");
-                       if (buf != NULL)
-                               isc_buffer_free(&buf);
-                       if (bufsz > MAXDATA) {
-                               fprintf(stderr, "could not allocate enough "
-                                       "space for the rdata\n");
-                               exit(1);
-                       }
-                       result = isc_buffer_allocate(mctx, &buf, bufsz);
+               result = isc_lex_create(mctx, strlen(cmdline), &lex);
+               check_result(result, "isc_lex_create");
+               isc_buffer_init(&source, cmdline, strlen(cmdline));
+               isc_buffer_add(&source, strlen(cmdline));
+               result = isc_lex_openbuffer(lex, &source);
+               check_result(result, "isc_lex_openbuffer");
+               result = isc_buffer_allocate(mctx, &buf, MAXWIRE);
+               check_result(result, "isc_buffer_allocate");
+               result = dns_rdata_fromtext(rdata, rdataclass, rdatatype, lex,
+                                           rn, ISC_FALSE, mctx, buf,
+                                           &callbacks);
+               isc_lex_destroy(&lex);
+               if (result == ISC_R_SUCCESS) {
+                       isc_buffer_usedregion(buf, &r);
+                       result = isc_buffer_allocate(mctx, &newbuf, r.length);
                        check_result(result, "isc_buffer_allocate");
-                       result = dns_rdata_fromtext(rdata, rdataclass,
-                                                   rdatatype,
-                                                   lex, rn, ISC_FALSE, mctx,
-                                                   buf, &callbacks);
-                       bufsz *= 2;
-                       isc_lex_destroy(&lex);
-               } while (result == ISC_R_NOSPACE);
-               dns_message_takebuffer(msg, &buf);
-               if (result != ISC_R_SUCCESS) {
+                       isc_buffer_putmem(newbuf, r.base, r.length);
+                       isc_buffer_usedregion(newbuf, &r);
+                       dns_rdata_fromregion(rdata, rdataclass, rdatatype, &r);
+                       isc_buffer_free(&buf);
+                       dns_message_takebuffer(msg, &newbuf);
+               } else {
                        fprintf(stderr, "invalid rdata format: %s\n",
                                isc_result_totext(result));
+                       isc_buffer_free(&buf);
                        return (STATUS_SYNTAX);
                }
        } else {