dash.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Declaring local variables inside while loop leads to memory leak
@ 2016-07-26 10:35 Vladimir Didenko
  2016-07-26 21:35 ` Jilles Tjoelker
  0 siblings, 1 reply; 2+ messages in thread
From: Vladimir Didenko @ 2016-07-26 10:35 UTC (permalink / raw)
  To: dash

Hi.

I found that declaring local variables inside while loop leads to
memory leak. Code sample:

test()
{
   while [ true ]; do
      local a=
   done
}

test

-- 
Regards,
Vladimir.

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Declaring local variables inside while loop leads to memory leak
  2016-07-26 10:35 Declaring local variables inside while loop leads to memory leak Vladimir Didenko
@ 2016-07-26 21:35 ` Jilles Tjoelker
  0 siblings, 0 replies; 2+ messages in thread
From: Jilles Tjoelker @ 2016-07-26 21:35 UTC (permalink / raw)
  To: Vladimir Didenko; +Cc: dash

On Tue, Jul 26, 2016 at 01:35:53PM +0300, Vladimir Didenko wrote:
> I found that declaring local variables inside while loop leads to
> memory leak. Code sample:

> test()
> {
>    while [ true ]; do
>       local a=
>    done
> }

> test

This can indeed consume a lot of memory. The memory is freed when the
function returns.

This could be fixed by adding a check before making a variable local but
that might make functions with many distinct locals slower.

Also note that the problem does not occur if local is used at the top of
a function only, as recommended by the man page.

-- 
Jilles Tjoelker

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-07-26 21:44 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-07-26 10:35 Declaring local variables inside while loop leads to memory leak Vladimir Didenko
2016-07-26 21:35 ` Jilles Tjoelker

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).