Hi,
This is really a usage question - of how to use Devel::Leak to demonstrate memory leaks - instigated by a post by Tels on the same topic last week (blame him :-)
------------------------------------ use warnings; use strict; use Devel::Leak;
use Inline C => Config => BUILD_NOISY => 1;
use Inline C => <<'EOC';
char * leaker1(int s) { char * r; int i;
Newz(1, r, sizeof(char) * s, char); if(r == NULL) croak("Failed to allocate memory in leaker1()");
for(i = 0; i < s-1; ++i) r[i] = 50;
return r; }
SV * leaker2(int s) { char * r; int i;
Newz(1, r, sizeof(char) * s, char); if(r == NULL) croak("Failed to allocate memory in leaker1()");
for(i = 0; i < s-1; ++i) r[i] = 50;
return newSVpv(r, 0); }
EOC
my $leakhandle; my $leakcount = Devel::Leak::NoteSV($leakhandle);
leaktest1();
print "Leaked ", Devel::Leak::CheckSV($leakhandle) - $leakcount, " things\n";
# $leakcount = Devel::Leak::NoteSV($leakhandle);
#leaktest2();
#print "Leaked ", Devel::Leak::CheckSV($leakhandle) - $leakcount, " things\n";
sub leaktest1{ for(2..5000) { my $str = leaker1($_); } print "Leaving leaktest1()\n"; }
sub leaktest2{ for(2..5000) { my $str = leaker2($_); } print "Leaving leaktest2()\n"; }
__END__
As I understand it, both the leaker1() and leaker2() functions will leak memory, but I'm unable to get Devel::Leak to report it using the above script.
If I run either the leaktest1() or the leaktest2() subroutine then I get a report of 0 leakages. Things can get a little crazy if I run both subroutines in the one execution of the script. If I don't reset $leakcount between the running of leaktest1() and leaktest2(), then leaktest1() still reports 0 leakages, but leaktest2() dumps out the addresses of a number of leaked items - and then the script segfaults.
If I *do* reset $leakcount between the running of the 2 subs, then both leaktest1() and leaktest2() again report a leakage 0 items.
Well .... I don't really need an explanation of *all* of that .... if someone can just show me the correct way to demonstrate the memory leaking capability of the code using Devel::Leak, that would be great .... that is, if it *can* be done.
Cheers, Rob
--
Any emails containing attachments will be deleted from my ISP's mail server before I even get to see them. If you wish to email me an attachment, please provide advance warning so that I can make the necessary arrangements.