On Sun, 10 Sep 2000, Matt Sergeant wrote:

> For 2 days solid now I've been trying to track down a very bizarre memory
> leak in AxKit.
> 
> I've checked everything I can think of - all circular references are now
> gone, all closures clean up carefully after themselves, and I've reduced
> the usage of some external modules. But still the processes grow.
> 
> Now to the wierd bit. I could track this down if it wasn't for this:
> 
> The memory leak starts after the Nth hit, usually around 35. This is
> running under httpd -X.
> 
> So it goes along very happily for 35 hits - memory usage is rock solid
> stable. Then after the 35th hit the memory usage starts to grow about 4k
> per hit. Obviously thats an impossible rate of growth to sustain for any
> amount of time, and soon the server is swamped.

you're leaking on every request, consider this example:
use strict;
my $i = 0;
my @a;
my $old_size = proc_size();

while (++$i) {
    my $size = proc_size();
    if ($size != $old_size) {
        printf "Size changed from $old_size to $size, i=$i\n";
        $old_size = $size;
        <>; #pause
    }
    push @a, [];
}

sub proc_size {
    my $size = 0;
    open my $fh, "</proc/self/status";
    while (<$fh>) {
        last if (($size) = (/^VmRSS:\s+(\d+)/));
    }
    close $fh;
    $size;
}

outputs:
Size changed from 1376 to 1436, i=1

Size changed from 1436 to 1472, i=2

Size changed from 1472 to 1476, i=55

Size changed from 1476 to 1480, i=99

Size changed from 1480 to 1484, i=158

Size changed from 1484 to 1488, i=204

> Time::HiRes, Apache::* (core apache stuff only), AxKit, Digest::MD5,
> Compress::Zlib, Fcntl, XML::Parser, XML::XPath, Unicode::Map8,
> Unicode::String, MIME::Base64, Storable (loaded but not used),
> XML::Sablotron (loaded but not used).

look for xsubs in those modules you're using that are calling
new{SV,AV,HV,RV} or SvREFCNT_inc().  sounds like botched refcnting or
failure to mortalize a new*V.
actually, my first guess is Apache::ModuleConfig->get, if you don't
explicitly pass __PACKAGE__ as the last argument, perl_eval_pv() is
called, which has a leak plugged in perl-current:

[  6201] By: gsar                                  on 2000/06/06  00:42:59
        Log: Perl_eval_pv() leaks 4 bytes every time it is called because it
             does a PUSHMARK that's never ever POPMARKed; in general, only
             Perl_call_[sp]v() need a PUSHMARK for incoming arguments;
             Perl_eval_[sp]v() don't because they don't take any incoming
             arguments (this leak has been around since the original version
             of perl_eval_pv() in 5.003_97e)
     Branch: perl
           ! perl.c

so first try changing:
Apache::ModuleConfig->get($r)
 to
Apache::ModuleConfig->get($r, __PACKAGE__)

Reply via email to