[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Memory leak
From: |
Aharon Robbins |
Subject: |
Re: Memory leak |
Date: |
Thu, 16 Apr 2009 21:02:23 +0300 |
User-agent: |
Heirloom mailx 12.4 7/29/08 |
Hi. Re this:
Aleksey Cheusov <address@hidden> wrote:
> The following test programs shows that there is a memory leak somewhere
> in GAWK.
>
> #!/usr/bin/gawk -f
>
> BEGIN {
> val_hash1 [1] = 1
>
> # for (j=1; j<=100000000; j++) {
> for (j=1; j<=1000000; j++) {
> test2( val_hash1 )
> }
> }
>
> function test2 (ValHash1, i)
> {
> for (i in ValHash1) {
> return # *** #
> }
> }
>
> This program fails like this.
>
> 0 cheusov>gawk -f ~/tmp/2.awk
> gawk: /home/cheusov/tmp/2.awk:16: fatal: push_forloop: loop_stack: can't
> allocate 25165824 bytes of memory (Cannot allocate memory)
> 2 cheusov>
>
> After changing 'return' statement marked as '# *** #' to 'break',
> everything works fine.
>
> The problem is reproducinble under NetBSD and Linux.
> --
> Best regards, Aleksey Cheusov.
This is indeed a bug. Here is a patch. It will shortly make its way
into the CVS version.
Thanks for reporting this,
Arnold
---------------------------------------------------
--- ../gawk-3.1.6/eval.c 2007-08-11 22:39:49.000000000 +0300
+++ eval.c 2009-04-16 20:58:04.000000000 +0300
@@ -1789,6 +1789,7 @@
int volatile save_loop_tag_valid = FALSE;
NODE *save_ret_node;
extern NODE *ret_node;
+ size_t current_nloops_active = 0;
/* tree->rnode is a Node_val giving function name */
/* tree->lnode is Node_expression_list of calling args. */
@@ -1831,12 +1832,16 @@
loop_tag_valid = FALSE;
}
PUSH_BINDING(func_tag_stack, func_tag, func_tag_valid);
+ current_nloops_active = nloops_active;
save_ret_node = ret_node;
ret_node = Nnull_string; /* default return value */
INCREMENT(f->exec_count); /* count function calls */
if (setjmp(func_tag) == 0)
(void) interpret(f->rnode);
+ while (nloops_active > current_nloops_active)
+ pop_forloop();
+
r = ret_node;
ret_node = (NODE *) save_ret_node;
RESTORE_BINDING(func_tag_stack, func_tag, func_tag_valid);