Memory leak in Perl 5.10 on Solaris 10 with %ENV

$ cat leak.pl
sub memused { return `pmap $$|tail -1|awk '{print \$2}'` }

for (my $i=1; 1 or $i<50; $i++) {
do {
local %ENV = %ENV; # <==== this is the leak !
$ENV{HOME} = "/tmp";
};
print " --->> $i iterations --- mem used --->> ", memused()
unless $i % 10000;
}

$ uname -a
SunOS hikaru 5.10 Generic_118833-24 sun4u sparc SUNW,Sun-Fire-V240
$ perl-5.10.0 leak.pl
--->> 10000 iterations --- mem used --->> 59816K
--->> 20000 iterations --- mem used --->> 108968K
--->> 30000 iterations --- mem used --->> 162216K
--->> 40000 iterations --- mem used --->> 215464K
--->> 50000 iterations --- mem used --->> 264616K
...

However, on Solaris 9:
$ uname -a
SunOS hikaru 5.10 Generic_118833-24 sun4u sparc SUNW,Sun-Fire-V240
$ perl-5.10.0 leak.pl
--->> 10000 iterations --- mem used --->> 4504K
--->> 20000 iterations --- mem used --->> 4504K
--->> 30000 iterations --- mem used --->> 4504K
--->> 40000 iterations --- mem used --->> 4504K
...

Perl 5.8.6 behavior on Solaris 10 is fine:
$ perl-5.8.6 leak.pl
--->> 10000 iterations --- mem used --->> 4072K
--->> 20000 iterations --- mem used --->> 4072K
--->> 30000 iterations --- mem used --->> 4072K
--->> 40000 iterations --- mem used --->> 4072K
...

Recompiling Perl 5.10 without -DPERL_USE_SAFE_PUTENV solved the problem.
So, is -DPERL_USE_SAFE_PUTENV known to be unsafe on Solaris 10? Maybe
depending on the Solaris 10 patchlevel?

--
albert chin (china [at] at [at] thewrittenword .dot. com)
Albert Chin [ Do, 10 Januar 2008 15:58 ] [ ID #1904900 ]

Re: Memory leak in Perl 5.10 on Solaris 10 with %ENV

On Jan 10, 9:58 am, Albert Chin <ch... [at] thewrittenword.com> wrote:
> $ cat leak.pl
> sub memused { return `pmap $$|tail -1|awk '{print \$2}'` }
>
> for (my $i=1; 1 or $i<50; $i++) {
> do {
> local %ENV = %ENV; # <==== this is the leak !
> $ENV{HOME} = "/tmp";
> };
> print " --->> $i iterations --- mem used --->> ", memused()
> unless $i % 10000;
>
> }
>
> $ uname -a
> SunOS hikaru 5.10 Generic_118833-24 sun4u sparc SUNW,Sun-Fire-V240
> $ perl-5.10.0 leak.pl
> --->> 10000 iterations --- mem used --->> 59816K
> --->> 20000 iterations --- mem used --->> 108968K
> --->> 30000 iterations --- mem used --->> 162216K
> --->> 40000 iterations --- mem used --->> 215464K
> --->> 50000 iterations --- mem used --->> 264616K
> ...
>
> However, on Solaris 9:
> $ uname -a
> SunOS hikaru 5.10 Generic_118833-24 sun4u sparc SUNW,Sun-Fire-V240
> $ perl-5.10.0 leak.pl
> --->> 10000 iterations --- mem used --->> 4504K
> --->> 20000 iterations --- mem used --->> 4504K
> --->> 30000 iterations --- mem used --->> 4504K
> --->> 40000 iterations --- mem used --->> 4504K
> ...
>
> Perl 5.8.6 behavior on Solaris 10 is fine:
> $ perl-5.8.6 leak.pl
> --->> 10000 iterations --- mem used --->> 4072K
> --->> 20000 iterations --- mem used --->> 4072K
> --->> 30000 iterations --- mem used --->> 4072K
> --->> 40000 iterations --- mem used --->> 4072K
> ...
>
> Recompiling Perl 5.10 without -DPERL_USE_SAFE_PUTENV solved the problem.
> So, is -DPERL_USE_SAFE_PUTENV known to be unsafe on Solaris 10? Maybe
> depending on the Solaris 10 patchlevel?
>
> --
> albert chin (china [at] at [at] thewrittenword .dot. com)

Perl on Solaris 10 has a bug in the handling of ENV. If you try to
make
the ENV larger, you will likely get an out-of-memory error. The fix is
to allocate new memory when ENV is changed - which leaks the old
memory.

http://www.nntp.perl.org/group/perl.perl5.porters/2005/10/ms g105366.html

--S
smallpond [ Do, 10 Januar 2008 17:07 ] [ ID #1904902 ]

Re: Memory leak in Perl 5.10 on Solaris 10 with %ENV

[A complimentary Cc of this posting was sent to
smallpond
<smallpond [at] juno.com>], who wrote in article <4d1c20c7-d073-4d29-8545-dc4881e735fd [at] m34g2000hsf.googlegroups.com>:
> Perl on Solaris 10 has a bug in the handling of ENV. If you try to
> make
> the ENV larger, you will likely get an out-of-memory error. The fix is
> to allocate new memory when ENV is changed - which leaks the old
> memory.
>
> http://www.nntp.perl.org/group/perl.perl5.porters/2005/10/ms g105366.html

If it causes a memory leak, it is not a fix, but a bug. The code in
question keeps a constant ENV memory footprint (it just flips to 0 and
back). IMO, when allocating new memory, Perl should keep the log of
the size allocated.

Hope this helps,
Ilya
Ilya Zakharevich [ Do, 10 Januar 2008 22:01 ] [ ID #1904909 ]
Perl » comp.lang.perl.misc » Memory leak in Perl 5.10 on Solaris 10 with %ENV

Vorheriges Thema: Sending HTML (MIME) email with Net::SMTP ?
Nächstes Thema: FAQ 7.21 How do I redefine a builtin function, operator, or method?