dash.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Harald van Dijk <harald@gigawatt.nl>
To: Vitaly Zuevsky <vitaly.zuevsky@gmail.com>,
	'Andrej Shadura' <andrew@shadura.me>,
	953421@bugs.debian.org, dash@vger.kernel.org
Cc: 'Debian Bug Tracking System' <submit@bugs.debian.org>
Subject: Re: Bug#953421: dash: Resident Set Size growth is unbound (memory leak) on an infinite shell loop
Date: Sun, 29 Mar 2020 20:06:31 +0100	[thread overview]
Message-ID: <a2efaae8-db1b-39ae-d7c2-8d119a4f14d4@gigawatt.nl> (raw)
In-Reply-To: <07ce01d605f3$103f1610$30bd4230$@gmail.com>

Hi Vitaly,

On 29/03/2020 18:54, Vitaly Zuevsky wrote:
> I have now fixed this bug locally.
> 
> The leak is in jobtab array (jobs.c). I concluded that the most logical approach would be eliminating inconsistency between makejob() and dowait() functions. My fix in a forked repo:
> 
> https://salsa.debian.org/psvz-guest/dash/-/commit/5e3ea90cb3355d1308c482661a471883d36af5e7

This change is incorrect. The reason dash keeps on allocating memory is 
because dash needs to keep on allocating memory. Consider this script:

   set -- $(seq 1 100)
   for i
   do
     : &
     sleep .1
   done
   for i
   do
     wait %$i
   done

This is a valid script and works fine in dash. Your change breaks this 
by not keeping the jobs around long enough, and I hope this test script 
shows that there is no way to keep the jobs around long enough but by 
allocating ever more memory.

Your change makes it impossible to keep track of the background 
process's status, but if you do not care about that anyway, you can 
avoid the increasing memory use without modifying dash by launching a 
background process without including it in the current shell's job 
table, by launching it from a subshell:

   while true
   do
     (true &)
     sleep .1
   done

Cheers,
Harald van Dijk

  reply	other threads:[~2020-03-29 19:08 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <158376996556.31988.8584094104007124674.reportbug@ec2-34-240-101-198.eu-west-1.compute.amazonaws.com>
     [not found] ` <CACujMDPfs5mJs8CVaxqM6wkCRANYQ71wTUkvHiNvOg+MPSTECQ@mail.gmail.com>
2020-03-29 17:54   ` Bug#953421: dash: Resident Set Size growth is unbound (memory leak) on an infinite shell loop Vitaly Zuevsky
2020-03-29 19:06     ` Harald van Dijk [this message]
2020-03-29 22:07       ` Jilles Tjoelker
2020-03-29 23:07         ` Harald van Dijk
2020-03-31 19:07       ` Vitaly Zuevsky
2020-03-31 21:04         ` Harald van Dijk
2020-04-02 13:18       ` Vitaly Zuevsky

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=a2efaae8-db1b-39ae-d7c2-8d119a4f14d4@gigawatt.nl \
    --to=harald@gigawatt.nl \
    --cc=953421@bugs.debian.org \
    --cc=andrew@shadura.me \
    --cc=dash@vger.kernel.org \
    --cc=submit@bugs.debian.org \
    --cc=vitaly.zuevsky@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).