bug-gnu-utils
[Top][All Lists]
Advanced

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

Re: gawk 3.1.0 memory leak


From: Aharon Robbins
Subject: Re: gawk 3.1.0 memory leak
Date: Fri, 3 Aug 2001 13:34:40 +0300

Greetings. Re this:

> Date: Wed, 1 Aug 2001 03:29:19 -0700
> From: "John H. DuBois III" <address@hidden>
> To: address@hidden
> Subject: gawk 3.1.0 memory leak
>
> Under SCO OpenServer 5.0.6a using gawk 3.1.0 compiled with gcc 2.95.2,
> this program:
>
> BEGIN {
>     foo(x)
>     x[""]
> }
> {
>     bar(x)
> }
> function foo(x) {
> }
> function bar(x) {
> }
>
> leaks 16 bytes per record processed.
> Is this a known problem?

This is a bug.  Below is an unofficial patch that fixes it for me.

Much thanks for the excellent bug report.

Arnold

*** ../gawk-3.1.0/eval.c        Tue May 15 08:56:31 2001
--- eval.c      Fri Aug  3 13:31:04 2001
***************
*** 1321,1337 ****
                        old_type = arg->type;
  
                        /*
!                        * subtlety: if arg->type is Node_var but n->type
!                        * is Node_var_array, then the array routines noticed
!                        * that a variable name was really an array and
!                        * changed the type.  But when v->name was pushed
!                        * on the stack, it came out of the varnames array,
!                        * and was not malloc'ed, so we shouldn't free it.
!                        * See the corresponding code in push_args().
!                        * Thanks to Juergen Kahrs for finding a test case
!                        * that shows this.
                         */
!                       if (old_type == Node_var_array || old_type == 
Node_array_ref)
                                free(n->vname);
  
                        if (arg->type == Node_var) {
--- 1319,1332 ----
                        old_type = arg->type;
  
                        /*
!                        * We only free n->vname in the same cases in 
push_fcall() which
!                        * mallocs it.  These are when passing a real array in; 
the
!                        * old type is array and the parameter "copy" is an 
array ref,
!                        * or when passing an array reference on to another 
function.
!                        * It helps to be awake when writing code.
                         */
!                       if (  (old_type == Node_var_array && n->type == 
Node_array_ref)
!                          || (old_type == Node_array_ref && n->type == 
Node_array_ref) )
                                free(n->vname);
  
                        if (arg->type == Node_var) {



reply via email to

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