On Fri Jan 05 08:31:09 2018, PEVANS wrote:
Show quoted text> On Fri Jan 05 05:32:30 2018, ivrntsv@yandex.ru wrote:
> > Skiming through code I saw a call to newSViv function without
> > mortalizing result.
> >
> > In ListUtils.xs, in sum XS:
> > if(!items)
> > switch(ix) {
> > case 0: XSRETURN_UNDEF;
> > case 1: ST(0) = newSViv(0); XSRETURN(1);
> > case 2: ST(0) = newSViv(1); XSRETURN(1);
> > }
> >
> > $ perl5.26.1 -mList::Util=sum0 -e 'sum0 while 1'
> > $ perl5.26.1 -mList::Util=product -e 'product while 1'
> >
> > It leaks.
>
> Ahyes, good catch. That wants some sv_2mortal()ing adding there.
This should fix it.
Before:
$ perl -MList::Util=sum0 -MDevel::MAT::Dumper=-dump_at_END -e 'sum0 for 1..1E5'
Dumping to /home/leo/src/perl/Scalar-List-Utils/perl-e.pmat because of END
$ pmat perl-e.pmat count
Perl memory dumpfile from perl 5.26.1
Heap contains 102568 objects
Kind Count (blessed)
ARRAY 196
CODE 227
GLOB 384
HASH 57 1
INVLIST 31
IO 8 8
PAD 106
REF 20
REGEXP 82 3
SCALAR 101408
STASH 49
^-- note the accumulation of just over 100000 SCALAR SVs.
After:
$ perl -Mblib -MList::Util=sum0 -MDevel::MAT::Dumper=-dump_at_END -e 'sum0 for 1..1E5'
Dumping to /home/leo/src/perl/Scalar-List-Utils/perl-e.pmat because of END
$ pmat perl-e.pmat count
Perl memory dumpfile from perl 5.26.1
Heap contains 2973 objects
Kind Count (blessed)
ARRAY 227
CODE 243
GLOB 429
HASH 64 3
INVLIST 31
IO 8 8
PAD 122
REF 24
REGEXP 97 3
SCALAR 1678
STASH 50
^-- no more accumulation of SCALARs.
--
Paul Evans