Bug 1011838 - expect leaks memory when using -re
expect leaks memory when using -re
Status: CLOSED CURRENTRELEASE
Product: Red Hat Enterprise Linux 6
Classification: Red Hat
Component: expect (Show other bugs)
6.5
All Linux
high Severity high
: rc
: ---
Assigned To: Vitezslav Crhonek
BaseOS QE - Apps
: TestBlocker, ZStream
Depends On:
Blocks: 1014624 1025199 1025202
  Show dependency treegraph
 
Reported: 2013-09-25 04:39 EDT by Jan Stancek
Modified: 2014-04-14 13:58 EDT (History)
8 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
: 1014624 (view as bug list)
Environment:
Last Closed: 2013-11-14 05:40:06 EST
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description Jan Stancek 2013-09-25 04:39:33 EDT
Description of problem:
Using -re appears to lead to memory leaks in expect, its memory usage keeps going up indefinitely:

Example:
---------------------------------
#!/usr/bin/expect

spawn yes
log_user 0

while 1 {
   expect {
       -re ".+?\n" {
	   #
       }
   }
}
---------------------------------

Running script above for couple seconds leads to:
PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+ COMMAND
19334 root      20   0 1075m 606m  688 R 93.4 69.8   1:44.81 expect

Version-Release number of selected component (if applicable):
expect-5.44.1.15-4.el6.x86_64

How reproducible:
100%

Steps to Reproduce:
1. run attached reproducer

Actual results:
expect memory usage keeps going up

Expected results:
expect memory usage should be stable

Additional info:
Reported also here: http://sourceforge.net/p/expect/patches/13/
Comment 3 Jan Stancek 2013-09-25 07:02:49 EDT
The patch from page linked in comment 0 makes the issue go away:

diff --git a/expect.c b/expect.c
index 65e6e04..185f9f3 100644
--- a/expect.c
+++ b/expect.c
@@ -185,9 +185,9 @@ free_ecase(
 {
     if (ec->i_list->duration == EXP_PERMANENT) {
        if (ec->pat)  { Tcl_DecrRefCount(ec->pat); }
-       if (ec->gate) { Tcl_DecrRefCount(ec->gate); }
        if (ec->body) { Tcl_DecrRefCount(ec->body); }
     }
+    if (ec->gate) { Tcl_DecrRefCount(ec->gate); }
 
     if (free_ilist) {
        ec->i_list->ecount--;

Used memory is holding stable at:
PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
31889 root      20   0  112m 2308 1796 R 94.5  0.3   1:43.09 expect
Comment 4 Vitezslav Crhonek 2013-09-25 07:11:53 EDT
Thank you for bug report and investigation.

Note You need to log in before you can comment on or make changes to this bug.