Bug 1264101

Summary: memleaks
Product: Red Hat Enterprise Linux 7 Reporter: Martin Kyral <mkyral>
Component: bashAssignee: Siteshwar Vashisht <svashisht>
Status: CLOSED ERRATA QA Contact: Martin Kyral <mkyral>
Severity: medium Docs Contact:
Priority: medium    
Version: 7.1CC: isenfeld, jkejda
Target Milestone: rcKeywords: Patch
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: bash-4.2.46-26.el7 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of:
: 1297843 (view as bug list) Environment:
Last Closed: 2017-08-01 20:32:05 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Bug Depends On:    
Bug Blocks: 1380361    
Attachments:
Description Flags
valgrind log for repr1
none
valgrind log for repr4 none

Description Martin Kyral 2015-09-17 14:00:59 UTC
Description of problem:
The following scripts are making bash to leak memory (originally reproducers for ksh memleaks). Also, the scripts run significantly slower under bash than with ksh (may be caused by the leaks, though).

$ cat repr1.ksh
#!/usr/bin/ksh

function _hash {
        typeset w=([abc]=1 [def]=31534 [xyz]=42)
        print -u2 $w 2>&-
        # accessing the var will leak
}
function _array {
        typeset w=(1 31534 42)
        print -u2 $w 2>&-
        # unset w will prevent leak
}

pmap -x $$ |tail -1
for (( j=0; j<100; j++)); do
        for (( i=0; i<10000; i++)); do
               _hash
        done
        pmap -x $$ |tail -1
done
sleep 1

$ cat repr4.ksh
#!/usr/bin/ksh

function _hash {
        typeset w=([abc]=1 [def]=31534 [xyz]=42)
        print -u2 $w 2>&-
        # accessing the var will leak
}
function _array {
        typeset w=(1 31534 42)
        print -u2 $w 2>&-
        # unset w will prevent leak
}

pmap -x $$ |tail -1
for (( j=0; j<100; j++)); do
        for (( i=0; i<10000; i++)); do
               _array
        done
        pmap -x $$ |tail -1
done
sleep 1

Version-Release number of selected component (if applicable):
bash-4.2.46-19.el7

How reproducible:
Always


Steps to Reproduce:
1. run the scripts from description
2.
3.

Actual results:
Memory usage grows quickly:
$ bash repr1.ksh
total kB          115060    3152     252
total kB          117964    6096    3196
total kB          120868    8912    6012
total kB          123640   11724    8824
total kB          126412   14536   11636
^C
$ bash repr4.ksh
total kB          115060    3152     256
total kB          117964    6096    3200
total kB          120868    8912    6016
total kB          123640   11724    8828
total kB          126412   14536   11640
^C
$


Expected results:
Steady memory usage as is with ksh:
$ ksh repr1.ksh
total kB          116848    1728     292
total kB          116848    1860     312
total kB          116848    1860     312
total kB          116848    1860     312
total kB          116848    1860     312
total kB          116848    1860     312
total kB          116848    1860     312
total kB          116848    1860     312
total kB          116848    1860     312
total kB          116848    1860     312
^C
$ ksh repr4.ksh
total kB          116848    1720     288
total kB          116848    1852     308
total kB          116848    1852     308
total kB          116848    1852     308
total kB          116848    1852     308
total kB          116848    1852     308
total kB          116848    1852     308
total kB          116848    1852     308
total kB          116848    1852     308
total kB          116848    1852     308
total kB          116848    1852     308
total kB          116848    1852     308
total kB          116848    1852     308
^C



Additional info:

Comment 1 Martin Kyral 2015-09-22 09:29:21 UTC
Created attachment 1075752 [details]
valgrind log for repr1

Comment 2 Martin Kyral 2015-09-22 09:29:47 UTC
Created attachment 1075753 [details]
valgrind log for repr4

Comment 8 errata-xmlrpc 2017-08-01 20:32:05 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHSA-2017:1931