Memory leak in Perl 5.10 on Solaris 10 with %ENV

Memory leak in Perl 5.10 on Solaris 10 with %ENV

am 10.01.2008 15:58:22 von Albert Chin

$ 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@ thewrittenword .dot. com)

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

am 10.01.2008 17:07:44 von smallpond

On Jan 10, 9:58 am, Albert Chin 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@ 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

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

am 10.01.2008 22:01:48 von Ilya Zakharevich

[A complimentary Cc of this posting was sent to
smallpond
], who wrote in article <4d1c20c7-d073-4d29-8545-dc4881e735fd@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