Subject: | Memory Leak in Net::DNS::Packet |
Date: | Thu, 13 Dec 2012 14:50:25 +0100 |
To: | bug-Net-DNS [...] rt.cpan.org |
From: | Bert Wijnen <bwijnen [...] ripe.net> |
When using Net::DNS::Packet, like this:
while (input) { # I am processing some 3M DNS reponse packets.
# but even with 20K you can see the problem clearly
# We do have NSID data in the EDNS section.
# but I believe it happens on all response packets
...
if ($decode_packet) {
my $packet;
$packet = Net::DNS::Packet->new(\$data);
$packet->print;
# following 2 lines can be used to see that xbody point to $packet.
#print "$packet->{header}->{xbody}\n";
#print "$packet\n";
}
}
I am detecting a memory leak.
Turns out that packet->{header}=>{xbody} contains a pointer to the packter
itself. And so when $packet goes out of scope, the reference count is still 1.
I have bypassed it by doing
if ($decode_packet) {
my $packet;
$packet = Net::DNS::Packet->new(\$data);
$packet->print;
undef $packet->{header}->{xbody};
}
And now my memory leaks are gone.
I guess Packet should have a DESTROY method that does the undef
fo xbody, so that the packet can actually be garbage collected when
it goes out of scope.
--- version of Perl (output of 'perl -V' is best)
This is perl 5, version 12, subversion 3 (v5.12.3) built for darwin-multi-2level
Copyright 1987-2010, Larry Wall
Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5 source kit.
Complete documentation for Perl, including FAQ lists, should be found on
this system using "man perl" or "perldoc perl". If you have access to the
Internet, point your browser at http://www.perl.org/, the Perl Home Page.
--- version of Net::DNS
I tried versions 0.69 and 0.70
--- operating system type and version
MAC OS X 10.6.8
--- version of nameserver (if known)
response packets for NSID from kroot
--- exact text of error message or description of problem
--- the shortest possible program that exhibits the problem
see above, but probably need to process a response packet that has EDNS data.
--- the specific queries you're making, if the data is available to Internet nameservers
I can send a batch of packets if you want, but the bug seems pretty clear in my mind
Bert Wijnen