From 98e500ff3ceb035d9d42acf25aa365940cf47568 Mon Sep 17 00:00:00 2001 From: "Arnold D. Robbins" Date: Thu, 15 Aug 2019 21:19:50 +0300 Subject: Avoid memory growth in format_tree. --- ChangeLog | 13 +++++++++++++ builtin.c | 7 ++----- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index eced4196..603e9528 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2019-08-15 Arnold D. Robbins + + 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 Reduce memory usage by only compiling the IGNORECASE version of diff --git a/builtin.c b/builtin.c index 1c205aa4..503a386c 100644 --- a/builtin.c +++ b/builtin.c @@ -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: { -- cgit v1.2.3