Note: This bug is displayed in read-only format because the product is no longer active in Red Hat Bugzilla.
For bugs related to Red Hat Enterprise Linux 5 product line. The current stable release is 5.10. For Red Hat Enterprise Linux 6 and above, please visit Red Hat JIRA https://issues.redhat.com/secure/CreateIssue!default.jspa?pid=12332745 to report new issues.

Bug 618393

Summary: memory leak in bash reading files
Product: Red Hat Enterprise Linux 5 Reporter: david ahern <daahern>
Component: bashAssignee: Roman Rakus <rrakus>
Status: CLOSED ERRATA QA Contact: BaseOS QE - Apps <qe-baseos-apps>
Severity: medium Docs Contact:
Priority: low    
Version: 5.5CC: bnater, green, mhusnain, rvokal, tsmetana, tumeya
Target Milestone: rc   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
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 10:39:07 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Attachments:
Description Flags
patch for the memleak none

Description david ahern 2010-07-26 20:17:48 UTC
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 16:33:54 UTC
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 17:08:12 UTC
Fixed in bash-3.2-28.el5

Comment 6 Branislav NĂ¡ter 2011-04-14 05:59:03 UTC
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 09:33:28 UTC
    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-04 01:37:24 UTC
    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 10:39:07 UTC
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