bug-gawk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [bug-gawk] Increased RAM memory usage in gawk 5.0.1 compared to gawk


From: Andrew J. Schorr
Subject: Re: [bug-gawk] Increased RAM memory usage in gawk 5.0.1 compared to gawk 4.1.4
Date: Wed, 28 Aug 2019 16:08:00 -0400
User-agent: Mutt/1.5.21 (2010-09-15)

Here are some simpler test cases:

No bug:

bash-4.2$ cat /tmp/bug6.awk 
$1
bash-4.2$ yes | head -2 | ./gawk -f /tmp/bug6.awk 
y
y

Reference counting bug:

bash-4.2$ cat /tmp/bug5.awk 
"fubar" ~ $1
bash-4.2$ yes | head -2 | ./gawk -f /tmp/bug5.awk 
debug: purge_record saving field 1 with refcnt 2

Comparing the debugger dump output, here's where it differs:

No memory leak:

[     1:0x23fcfd8] Op_push_i           : 1 [MALLOC|NUMCUR|NUMBER|NUMINT]
[     1:0x23fcfb0] Op_field_spec       : 
[      :0x23fd050] Op_jmp_false        : [target_jmp = 0x23fd028]
[      :0x23fd078] Op_K_print_rec      : [redir_type = ""]

Memory leak:

[     1:0x256ef60] Op_push_i           : "fubar" [MALLOC|STRING|STRCUR]
[     1:0x256f000] Op_push_i           : 1 [MALLOC|NUMCUR|NUMBER|NUMINT]
[     1:0x256efd8] Op_field_spec       : 
[     1:0x256efb0] Op_match            : 
[      :0x256f050] Op_jmp_false        : [target_jmp = 0x256f028]
[      :0x256f078] Op_K_print_rec      : [redir_type = ""]

Op_field_spec calls r_get_field and then UPREF on $1.
Op_jmp_false evaluates the condition and then calls DEREF on the value
it considered. In the first case, that calls DEREF on $1.

In the second case, Op_match uses research to evaluate the regexp match
and then creates a new Boolean variable that it pushes onto the stack.
The Op_jmp_false considers this and DEREFs it. But it seems that DEREF
is never called on $1.

The DEREF under Op_match_rec is getting called on the lhs ("fubar"), but
the rhs ($1) is not getting a DEREF call.

This patch fixes my test case (bug5), but is not more generally correct (it
does not pass make check, dumping core on rebt8b2 and hanging on regexprange
and failing sortu):

diff --git a/interpret.h b/interpret.h
index 3215833..4820716 100644
--- a/interpret.h
+++ b/interpret.h
@@ -1065,6 +1065,8 @@ match_re:
                        if (op != Op_match_rec) {
                                decr_sp();
                                DEREF(t1);
+                               if (m->type == Node_dynregex)
+                                       DEREF(m->re_exp);
                        }
                        r = node_Boolean[di];
                        UPREF(r);

Arnold -- do you have any insight into the correct fix?

Regards,
Andy



reply via email to

[Prev in Thread] Current Thread [Next in Thread]