dash.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jilles Tjoelker <jilles@stack.nl>
To: Vladimir Didenko <vladimir.didenko@gmail.com>
Cc: dash@vger.kernel.org
Subject: Re: Declaring local variables inside while loop leads to memory leak
Date: Tue, 26 Jul 2016 23:35:06 +0200	[thread overview]
Message-ID: <20160726213506.GC16428@stack.nl> (raw)
In-Reply-To: <CAHRK1yP1GyUJEPNLSicUatRJPOJg=Oeac1daJkuJs6eDD+xi9Q@mail.gmail.com>

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

      reply	other threads:[~2016-07-26 21:44 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160726213506.GC16428@stack.nl \
    --to=jilles@stack.nl \
    --cc=dash@vger.kernel.org \
    --cc=vladimir.didenko@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).