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:
Created attachment 450520 [details] patch for the memleak This patch fixes the issue - it is backported bash40-033 official patch
Fixed in bash-3.2-28.el5
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.
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.
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.
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