diff options
author | Arnold D. Robbins <arnold@skeeve.com> | 2019-08-15 21:19:50 +0300 |
---|---|---|
committer | Arnold D. Robbins <arnold@skeeve.com> | 2019-08-15 21:19:50 +0300 |
commit | 98e500ff3ceb035d9d42acf25aa365940cf47568 (patch) | |
tree | 8c33627bfe255de53f76d4e38f3fe07ca58d15dc | |
parent | c7c3998ed9d96b61d03c675b2105ca5da77b9bfd (diff) | |
download | egawk-98e500ff3ceb035d9d42acf25aa365940cf47568.tar.gz egawk-98e500ff3ceb035d9d42acf25aa365940cf47568.tar.bz2 egawk-98e500ff3ceb035d9d42acf25aa365940cf47568.zip |
Avoid memory growth in format_tree.
-rw-r--r-- | ChangeLog | 13 | ||||
-rw-r--r-- | builtin.c | 7 |
2 files changed, 15 insertions, 5 deletions
@@ -1,3 +1,16 @@ +2019-08-15 Arnold D. Robbins <arnold@skeeve.com> + + Revert a6df7afc605079df7d85318846a522ef64aaa44d, change of + 2016-05-03, which used realloc to shrink the buffer, in an + attempt to save memory. In actuality, it could cause increased + memory usage, even though there was no memory leak. See + https://lists.gnu.org/archive/html/bug-gawk/2019-08/msg00003.html + and the rest of thread for more detail. + + * builtin.c (format_tree): Don't use realloc, just call + make_str_node with the original buffer. Remove `olen_final' + variable and its use. + 2019-08-15 Andrew J. Schorr <aschorr@telemetry-investments.com> Reduce memory usage by only compiling the IGNORECASE version of @@ -685,7 +685,7 @@ format_tree( int i, nc; bool toofew = false; char *obuf, *obufout; - size_t osiz, ofre, olen_final; + size_t osiz, ofre; const char *chbuf; const char *s0, *s1; int cs1; @@ -1646,10 +1646,7 @@ mpf1: _("too many arguments supplied for format string")); } bchunk(s0, s1 - s0); - olen_final = obufout - obuf; - if (ofre > 0) - erealloc(obuf, char *, olen_final + 1, "format_tree"); - r = make_str_node(obuf, olen_final, ALREADY_MALLOCED); + r = make_str_node(obuf, obufout - obuf, ALREADY_MALLOCED); obuf = NULL; out: { |