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

People
Owner: Nobody in particular
Requestors: rwinslow [...] lbl.gov
Cc:
AdminCc:

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

Attachments


Subject: Memory leak in long running programs
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.
Download Telnet.pm.diff
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; < --- >
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 Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.