[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: possible gawk memory leak?
From: |
david kerns |
Subject: |
Re: possible gawk memory leak? |
Date: |
Fri, 25 Jun 2021 06:20:01 -0700 |
I think you've mis-labeled the behavior. A memory leak is when you allocate
some memory and then either don't free it, or fail to free all that you
allocated, which becomes most problematic when it's done in a loop.
the program you submitted is not leaking, it's just consuming all available
memory.
/dev/zero is an infinite generator of zeros
awk happily reads "record 1" into memory looking for the inevitable EOL/EOR
On Fri, Jun 25, 2021 at 6:06 AM Eckard Brauer <eckard.brauer@gmx.de> wrote:
> Hello,
>
> playing around I just observed a little problem with gawk I can't
> really explain well (gawk-5.1.0, Linux (Gentoo), x86_64). Executing
>
> awk 'NR==4{exit}{print NR}' /dev/zero
>
> gawk tries to allocate all available memory and so freezes the whole
> host for some time. Doing that in a memory limited environment to
> preserve disk swapping only let's happen the crash earlier and without
> system freeze:
>
> $ ulimit -m 8192000
> $ ulimit -v 8192000
> $ awk 'NR==4{exit}{print NR}' /dev/zero
> awk: fatal: io.c:3464:grow_iop_buffer: iop->buf: cannot reallocate
> 8589934593 bytes of memory: Cannot allocate memory
>
> So if that's not an individual problem, could you either explain the
> reason(s) for that behaviour, or fix it if it's unintended?
>
> Thanks in advance && best regards,
> Eckard Brauer
>
>