Skip Menu |
 

This queue is for tickets about the Scalar-List-Utils CPAN distribution.

Report information
The Basics
Id: 124017
Status: patched
Priority: 0/
Queue: Scalar-List-Utils

People
Owner: Nobody in particular
Requestors: ivrntsv [...] yandex.ru
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: sum0 and product without arguments leak memory
Date: Fri, 05 Jan 2018 13:31:02 +0300
To: bug-scalar-list-utils [...] rt.cpan.org
From: Ivan Vorontsov <ivrntsv [...] yandex.ru>
Download (untitled) / with headers
text/plain 403b
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.
Download (untitled) / with headers
text/plain 569b
On Fri Jan 05 05:32:30 2018, ivrntsv@yandex.ru wrote: Show quoted text
> 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. -- Paul Evans
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
Subject: rt124017.patch
Download rt124017.patch
text/x-diff 479b
diff --git a/ListUtil.xs b/ListUtil.xs index a08582b..4f146f8 100644 --- a/ListUtil.xs +++ b/ListUtil.xs @@ -190,8 +190,8 @@ CODE: if(!items) switch(ix) { case 0: XSRETURN_UNDEF; - case 1: ST(0) = newSViv(0); XSRETURN(1); - case 2: ST(0) = newSViv(1); XSRETURN(1); + case 1: ST(0) = sv_2mortal(newSViv(0)); XSRETURN(1); + case 2: ST(0) = sv_2mortal(newSViv(1)); XSRETURN(1); } sv = ST(0);


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.