Skip Menu |

This queue is for tickets about the Net-Telnet CPAN distribution.

Report information
The Basics
Id: 5991
Status: rejected
Priority: 0/
Queue: Net-Telnet

Owner: Nobody in particular
Requestors: rwinslow [...]

Bug Information
Severity: Critical
Broken in: (no value)
Fixed in: (no value)


MIME-Version: 1.0
X-Mailer: MIME-tools 5.411 (Entity 5.404)
Subject: Memory leak in long running programs
Content-Type: multipart/mixed; boundary="----------=_1081838821-23786-0"
Content-Length: 0
Content-Type: text/plain
Content-Disposition: inline
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: iso-8859-1
Content-Length: 1158
Download (untitled) / with headers
text/plain 1.1k
Using PERL 5.8.2 on FreeBSD 4.8-RELEASE When Net::Telnet is used in a long running process where objects are created and torn down there is a memory leak that is occuring. "sub _fillbuf" at line 2145 calls sysread with a part of the telnet object as the buffer to fill. For some reason, I haven't had the time to find out what is really going on, memory is being allocated for each time line 2145 is called which can be multiple times depending on the size of return messages and the number of calls to functions that use this subroutine. A fix that works is to replace the object variable being used as the buffer location with a locally scoped "my" variable instead, copying the contents of the object buffer to the "my" variable, clearing the object buffer contents, continuing through the function using and operating on the "my" variable, and then near the end copying the contents of the "my" variable back into the object buffer. This has been tested in a daemon and has eliminated the memory leak encountered. I imagine that there is some performance hit but I haven't noticed any in the daemon this runs in. A diff file is attached.
Content-Type: application/octet-stream; name=""
Content-Disposition: inline; filename=""
Content-Transfer-Encoding: base64
Content-Length: 1326
text/x-diff 1.2k
57a58 > 2094,2099c2095 < < # Assign current buffer contents to a scoped variable ot prevent < # a memory leak that was occuring. 2004-04-09 rwinslow < my $_buf = $s->{buf}; < $s->{buf} = ""; < --- > 2113c2109 < unless length($_buf) <= $s->{maxbufsize}; --- > unless length($s->{buf}) <= $s->{maxbufsize}; 2142c2138 < $_buf .= $s->{pushback_buf}; --- > $s->{buf} .= $s->{pushback_buf}; 2147c2143 < $read_pos = length $_buf; --- > $read_pos = length $s->{buf}; 2149c2145 < $nread = sysread $self, $_buf, $s->{blksize}, $read_pos; --- > $nread = sysread $self, $s->{buf}, $s->{blksize}, $read_pos; 2167c2163 < &_log_dump('<', $s->{dumplog}, \$_buf, $read_pos); --- > &_log_dump('<', $s->{dumplog}, \$s->{buf}, $read_pos); 2171c2167 < if ($s->{telnet_mode} and index($_buf,"\377",$unparsed_pos) > -1) { --- > if ($s->{telnet_mode} and index($s->{buf},"\377",$unparsed_pos) > -1) { 2179c2175 < next if $unparsed_pos >= length $_buf; --- > next if $unparsed_pos >= length $s->{buf}; 2183c2179 < &_log_print($s->{inputlog}, substr($_buf, $unparsed_pos)); --- > &_log_print($s->{inputlog}, substr($s->{buf}, $unparsed_pos)); 2185,2189c2181 < < # Put the remaining contents of the buffer back into the telnet object < # 2004-04-09 rwinslow < $s->{buf} = $_buf; < --- >
MIME-Version: 1.0
X-Mailer: MIME-tools 5.427 (Entity 5.427)
Content-Disposition: inline
Content-Type: text/plain; charset="UTF-8"
Message-ID: <rt-3.8.HEAD-29064-1356352964-425.5991-0-0 [...]>
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
Content-Length: 108
Download (untitled) / with headers
text/plain 108b
This memory leak appears to be a bug in perl itself that has been fixed. Thanks for finding a work around.

This service is sponsored and maintained by Best Practical Solutions and runs on infrastructure.

Please report any issues with to