Bug 618393 - memory leak in bash reading files
memory leak in bash reading files
Status: CLOSED ERRATA
Product: Red Hat Enterprise Linux 5
Classification: Red Hat
Component: bash (Show other bugs)
5.5
All Linux
low Severity medium
: rc
: ---
Assigned To: Roman Rakus
BaseOS QE - Apps
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2010-07-26 16:17 EDT by david ahern
Modified: 2014-01-12 19:12 EST (History)
6 users (show)

See Also:
Fixed In Version: bash-3.2-28.el5
Doc Type: Bug Fix
Doc Text:
Bash had a memory leak in the "read" builtin when the number of fields being read was not equal to the number of variables passed as arguments, causing a shell script crash. This is fixed to prevent a memory leak and shell script crash.
Story Points: ---
Clone Of:
Environment:
Last Closed: 2011-07-21 06:39:07 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)
patch for the memleak (1.30 KB, patch)
2010-09-29 12:33 EDT, Roman Rakus
no flags Details | Diff

  None (edit)
Description david ahern 2010-07-26 16:17:48 EDT
Description of problem:
Bash is leaking memory on redirected reads ultimately leading to the crash of the shell script.

Version-Release number of selected component (if applicable):
tested with RHEL5.4 and RHEL5.5 both of which are using version bash-3.2-24.el5

How reproducible:
100%

Steps to Reproduce:
1. create a text file with a number of lines in it. In my case it is a 2M file with 4100 lines. (nothing magical about my input file -- just text)

2. get the pid of the shell: echo $$

3. run the following:
for n in $(seq 1 1000); do
   while read line; do
     echo $line; 
   done < /tmp/input-file > /dev/null 
done

4. in a separate login run:
while [ 1 ]; do egrep 'VmSiz|VmRSS' /proc/<pid>/status; sleep 2; done


Actual results:
VmRSS increases with time and memory not freed until shell exits.

Expected results:
memory consumption is flat

Additional info:
Comment 2 Roman Rakus 2010-09-29 12:33:54 EDT
Created attachment 450520 [details]
patch for the memleak

This patch fixes the issue - it is backported bash40-033 official patch
Comment 3 Roman Rakus 2011-03-03 12:08:12 EST
Fixed in bash-3.2-28.el5
Comment 6 Branislav Náter 2011-04-14 01:59:03 EDT
Bugfix was successfully verified on package bash-3.2-29.el5.x86_64 on all supported architectures (i386, x86_64, ia64, ppc, s390x).

No memory leak appears anymore, memory consumption is flat.
Comment 7 Misha H. Ali 2011-04-20 05:33:28 EDT
    Technical note added. If any revisions are required, please edit the "Technical Notes" field
    accordingly. All revisions will be proofread by the Engineering Content Services team.
    
    New Contents:
Previously bash had a memory leak in the "read" builtin when the number of fields being read was not the same as the number of variables passed as arguments. Ultimately, this caused the shell script to crash. This is now fixed to remove the memory leak and prevent the shell script from crashing unexpectedly.
Comment 8 Misha H. Ali 2011-05-03 21:37:24 EDT
    Technical note updated. If any revisions are required, please edit the "Technical Notes" field
    accordingly. All revisions will be proofread by the Engineering Content Services team.
    
    Diffed Contents:
@@ -1 +1 @@
-Previously bash had a memory leak in the "read" builtin when the number of fields being read was not the same as the number of variables passed as arguments. Ultimately, this caused the shell script to crash. This is now fixed to remove the memory leak and prevent the shell script from crashing unexpectedly.+Bash had a memory leak in the "read" builtin when the number of fields being read was not equal to the number of variables passed as arguments, causing a shell script crash. This is fixed to prevent a memory leak and shell script crash.
Comment 9 errata-xmlrpc 2011-07-21 06:39:07 EDT
An advisory has been issued which should help the problem
described in this bug report. This report is therefore being
closed with a resolution of ERRATA. For more information
on therefore solution and/or where to find the updated files,
please follow the link below. You may reopen this bug report
if the solution does not work for you.

http://rhn.redhat.com/errata/RHSA-2011-1073.html

Note You need to log in before you can comment on or make changes to this bug.