Bug 1245233

Summary: bash script shows memory leak
Product: [Fedora] Fedora Reporter: Martin Kyral <mkyral>
Component: bashAssignee: Ondrej Oprala <ooprala>
Status: CLOSED NEXTRELEASE QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: medium Docs Contact:
Priority: high    
Version: 22CC: admiller, ooprala, ovasik
Target Milestone: ---   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: 4.3.42-1.fc21 Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: 126161 Environment:
Last Closed: 2015-08-05 22:25:06 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:

Description Martin Kyral 2015-07-21 14:19:58 UTC
This ancient bug has been reintroduced in fedora:

$ cat loop.sh
#!/bin/bash
run() { local -a A=(); local -a A=(); }
while :; do run; done

$ cat test2.sh
#!/bin/bash
$(readlink /proc/$$/exe) loop.sh &
SHPID=$!
sleep 1
MEM=$(ps p $SHPID o "%z" | grep -v VSZ)
echo "memory consumption: $MEM"
sleep 15
MEM2=$(ps p $SHPID o "%z" | grep -v VSZ)
kill $SHPID
echo "memory consumption: $MEM2"
#compare memory consumption
[ $MEM -eq $MEM2 ]

$ bash test2.sh
memory consumption: 130292
memory consumption: 373304
$

In both RHEL6 and RHEL7 the test passes.

Version:
bash-4.3.39-3.fc22

+++ This bug was initially created as a clone of Bug #126161 +++

[root@localhost root]# bash --version
GNU bash, version 2.05b.0(1)-release (i386-redhat-linux-gnu)
Copyright (C) 2002 Free Software Foundation, Inc.

For testing purposes he uses:

---------------
#!/bin/bash
run() { local -a A=(); local -a A=(); }
while :; do run; done
---------------

This routine is eating up memory, which shows clearly 
in 'cat /proc/meminfo' or 'top'.

--- Additional comment from Bernd Schmidt on 2004-06-16 17:31:58 EDT ---

When make_local_variable finds an existing variable with the same name, it is
reused.  However, we never call array_dispose to free array data.  This patch
adds centralized freeing of all data for a reused local variable.

Comment 1 Fedora Update System 2015-08-03 10:15:04 UTC
bash-4.3.39-6.fc21 has been submitted as an update for Fedora 21.
https://admin.fedoraproject.org/updates/bash-4.3.39-6.fc21

Comment 2 Fedora Update System 2015-08-03 10:15:12 UTC
bash-4.3.39-6.fc22 has been submitted as an update for Fedora 22.
https://admin.fedoraproject.org/updates/bash-4.3.39-6.fc22

Comment 3 Fedora Update System 2015-08-03 10:15:20 UTC
bash-4.3.39-6.fc23 has been submitted as an update for Fedora 23.
https://admin.fedoraproject.org/updates/bash-4.3.39-6.fc23

Comment 4 Fedora Update System 2015-08-03 16:52:04 UTC
Package bash-4.3.39-6.fc23:
* should fix your issue,
* was pushed to the Fedora 23 testing repository,
* should be available at your local mirror within two days.
Update it with:
# su -c 'yum update --enablerepo=updates-testing bash-4.3.39-6.fc23'
as soon as you are able to.
Please go to the following url:
https://admin.fedoraproject.org/updates/FEDORA-2015-12688/bash-4.3.39-6.fc23
then log in and leave karma (feedback).

Comment 5 Fedora Update System 2015-08-05 22:25:06 UTC
bash-4.3.39-6.fc22 has been pushed to the Fedora 22 stable repository.  If problems still persist, please make note of it in this bug report.

Comment 6 Fedora Update System 2015-08-10 10:03:52 UTC
bash-4.3.39-6.fc23 has been pushed to the Fedora 23 stable repository.  If problems still persist, please make note of it in this bug report.

Comment 7 Fedora Update System 2015-08-18 14:07:16 UTC
bash-4.3.42-1.fc21 has been submitted as an update for Fedora 21.
https://admin.fedoraproject.org/updates/bash-4.3.42-1.fc21

Comment 8 Fedora Update System 2015-08-18 14:07:23 UTC
bash-4.3.42-1.fc22 has been submitted as an update for Fedora 22.
https://admin.fedoraproject.org/updates/bash-4.3.42-1.fc22

Comment 9 Fedora Update System 2015-08-18 14:07:36 UTC
bash-4.3.42-1.fc23 has been submitted as an update for Fedora 23.
https://admin.fedoraproject.org/updates/bash-4.3.42-1.fc23

Comment 10 Fedora Update System 2015-09-01 03:36:35 UTC
bash-4.3.42-1.fc23 has been pushed to the Fedora 23 stable repository. If problems still persist, please make note of it in this bug report.

Comment 11 Fedora Update System 2015-09-04 05:19:29 UTC
bash-4.3.42-1.fc22 has been pushed to the Fedora 22 stable repository. If problems still persist, please make note of it in this bug report.

Comment 12 Fedora Update System 2015-09-04 11:49:23 UTC
bash-4.3.42-1.fc21 has been pushed to the Fedora 21 stable repository. If problems still persist, please make note of it in this bug report.