Hide Forgot
Description of problem: Bash script memory utilization continually increases if bash internal pattern matching / substitution is used. Version-Release number of selected component (if applicable): [root@RHEL6-TEST mkandoll]# rpm -qi bash Name : bash Relocations: (not relocatable) Version : 4.1.2 Vendor: Red Hat, Inc. Release : 33.el6_7.1 Build Date: Mon 17 Aug 2015 03:51:51 Install Date: Fri 25 Mar 2016 04:26:05 PM MST Build Host: x86-027.build.eng Group : System Environment/Shells Source RPM: bash-4.1.2-33.el6_7.1.sr Size : 3142151 License: GPLv3+ Signature : RSA/8, Thu 20 Aug 2015 08:01:55 AM MST, Key ID 199e2f91fd431d51 Packager : Red Hat, Inc. <http://bugzilla.redhat.com/bugzilla> URL : http://www.gnu.org/software/bash Summary : The GNU Bourne Again shell How reproducible: Every time Steps to Reproduce: Reproduced using script: [root@RHEL6-BASIC mkandoll]# cat test17.sh #!/bin/bash while /bin/true do test="something1234" test=${test//[^a-zA-Z0-9_.]/} done Run script for some time using: nohup ./test17.sh 2>&1 > /dev/null & Watch using top. Actual results: Memory usage increases without bound. Expected results: Memory is allocated first time and saved for reuse later. Additional info: Reproduced on a test vm using Red Hat Enterprise Linux Server release 6.5 (Santiago) that I upgraded bash package to 33.el6_7.1. Seeing this in production servers running Red Hat Enterprise Linux Server release 6.7 (Santiago). Testing is not possible on production servers. For a workaround I am rewriting scripts that utilize this specific substitution to use echo piped to tr.
Fixed in RHEL7 (BZ#1172214) - "Bash made a system call to allocate memory twice for the same purpose, which caused Bash to leak memory." Patch (really stupid bug in bash 4.0-4.2): --- bash-4.1/subst.c 2015-04-07 10:00:00.482931289 +0900 +++ bash-4.1/subst.c 2015-04-07 10:01:28.258111134 +0900 @@ -7039,8 +7039,6 @@ ret = alloc_word_desc (); ret->word = temp1; - ret = alloc_word_desc (); - ret->word = temp1; if (temp1 && QUOTED_NULL (temp1) && (quoted & (Q_HERE_DOCUMENT|Q_DOUBLE_QUOTES))) ret->flags |= W_QUOTED|W_HASQUOTEDNULL; return ret; But RHEL6 still needs the patches applied.
Fixed in 4.1.2-35 (#1207042) Maybe change status to resolved/fixed?
*** This bug has been marked as a duplicate of bug 1207042 ***