Re: Bug#953421: dash: Resident Set Size growth is unbound (memory leak) on an infinite shell loop

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

 



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



[Index of Archives]     [LARTC]     [Bugtraq]     [Yosemite Forum]     [Photo]

  Powered by Linux