New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Substr in encode leaks memory #15871
Comments
From arza@arza.usCreated by arza@arza.usLeaks memory: perl -e 'use Encode; while (1) { encode("ascii", Perl Info
|
From @jkeenanOn Mon, 13 Feb 2017 02:11:21 GMT, arza@arza.us wrote:
Can you clarify how you detect or record the memory leak? Thank you very much. -- |
The RT System itself - Status changed from 'new' to 'open' |
From @shlomifHi all! On Mon, 13 Feb 2017 05:37:15 -0800, jkeenan wrote:
I cannot speak for arza (=the original reporter), but when I run «perl -e 'use Encode; while (1) { encode("ascii", substr("test",1)); }'» from the command line, then: 1. Using perl-5.22.3-1.mga6 (on mageia x86-64 v6), the RAM consumption in htop stays the same at 0.1% even after waiting a long time. 2. The RAM consumption of the perl process in htop using perl-5.24.1 from perlbrew consistently grows - I killed it after it occupied over 10% of my 8 GB of RAM. It appears that both VIRT and RES are steadily growing. |
From @jkeenanOn Mon, 13 Feb 2017 15:02:00 GMT, shlomif wrote:
Shlomi, thanks! Confirmed. Since this is a regression, I'm marking the ticket as a blocker for next 5.24 and 5.26 releases. Thank you very much. -- |
From @jkeenanOn Mon, 13 Feb 2017 02:11:21 GMT, arza@arza.us wrote:
I have not been able to figure out a way to use Porting/bisect.pl to bisect this problem, but manual bisection suggests that the bug emerged between these two commits in Jan 2016. b0248db looks okay -- |
From @jkeenanOn Mon, 13 Feb 2017 21:55:11 GMT, jkeenan wrote:
Manual bisection suggests that the following is the commit where, following Shlomi's suggestion, memory starts to leak: ##### [perl #126633] copy anything gmagical on the right Inline Patchdiff --git a/pp_hot.c b/pp_hot.c
index 650f06b..b80efae 100644
--- a/pp_hot.c
+++ b/pp_hot.c
@@ -1173,7 +1173,7 @@ S_aassign_copy_common(pTHX_ SV **firstlelem, SV **lastlelem,
svr = *relem;
assert(svr);
- if (UNLIKELY(SvFLAGS(svr) & SVf_BREAK || copy_all)) {
+ if (UNLIKELY(SvFLAGS(svr) & (SVf_BREAK|SVs_GMG) || copy_all)) {
#ifdef DEBUGGING
if (fake) {
@@ -1265,6 +1265,10 @@ PP(pp_aassign)
/* at least 2 LH and RH elements, or commonality isn't an issue */
if (firstlelem < lastlelem && firstrelem < lastrelem) {
+ for (relem = firstrelem+1; relem <= lastrelem; relem++) {
+ if (SvGMAGICAL(*relem))
+ goto do_scan;
+ }
for (lelem = firstlelem; lelem <= lastlelem; lelem++) {
if (*lelem && SvSMAGICAL(*lelem))
goto do_scan;
diff --git a/t/op/aassign.t b/t/op/aassign.t
index d6a1a42..03cc84c 100644
--- a/t/op/aassign.t
+++ b/t/op/aassign.t
@@ -345,9 +345,10 @@ SKIP: {
{ # magic handling, see #126633
use v5.22;
+ my $set;
package ArrayProxy {
sub TIEARRAY { bless [ $_[1] ] }
- sub STORE { $_[0][0]->[$_[1]] = $_[2] }
+ sub STORE { $_[0][0]->[$_[1]] = $_[2]; $set = 1 }
sub FETCH { $_[0][0]->[$_[1]] }
sub CLEAR { @{$_[0][0]} = () }
sub EXTEND {}
@@ -363,9 +364,7 @@ SKIP: {
@real = @base;
@real[0, 1] = @proxy[1, 0];
is($real[0], "b", "tied right first");
- { local $::TODO = "#126633";
is($real[1], "a", "tied right second");
- }
@real = @base;
@proxy[0, 1] = @proxy[1, 0];
is($real[0], "b", "tied both first");
@@ -379,6 +378,10 @@ SKIP: {
@real = @base;
($temp, @proxy) = @proxy[1, 0];
is($real[0], "a", "scalar/array tied both");
+ $set = 0;
+ my $orig;
+ ($proxy[0], $orig) = (1, $set);
+ is($orig, 0, 'previous value of $set');
}
done_testing();
Thank you very much. -- |
From @tonycozOn Sun, 12 Feb 2017 18:11:21 -0800, arza@arza.us wrote:
Encode isn't needed: ./perl -e 'sub foo { my ($x, $y) = @_; } while (1) { foo("abc", substr("test", 1)) }' produces the same leak, but: ./perl -e 'while (1) { my ($x, $y) = (substr("test", 1), "abc") }' doesn't leak which makes me suspect the lvalue created by pp_substr, though I haven't found the cause. Tony |
From arza@arza.usOn Mon, 13 Feb 2017 22:32:09 -0800, tonyc wrote:
The position matters: perl -e 'sub foo { my ($t1, $t2, $t3) = (shift, "", ""); } while (1) { foo(substr("test",1)); }' - no leak perl -e 'sub foo { my ($t1, $t2, $t3) = ("", "", shift(@_)); } while (1) { foo(substr("test",1)); }' - no leak -arza |
From @iabynOn Mon, Feb 13, 2017 at 10:32:10PM -0800, Tony Cook via RT wrote:
Now fixed by the following, which I've just pushed. A good candidate for commit 1050723 avoid a leak in list assign from/to magic values -- |
@iabyn - Status changed from 'open' to 'pending release' |
From @jmdhOn Wed, Feb 15, 2017 at 08:27:15AM -0800, Dave Mitchell via RT wrote:
I can confirm that this applies cleanly and fixes the leak on Debian's Cheers, |
From @khwilliamsonThank you for filing this report. You have helped make Perl better. With the release today of Perl 5.26.0, this and 210 other issues have been Perl 5.26.0 may be downloaded via: If you find that the problem persists, feel free to reopen this ticket. |
@khwilliamson - Status changed from 'pending release' to 'resolved' |
Migrated from rt.perl.org#130766 (status was 'resolved')
Searchable as RT130766$
The text was updated successfully, but these errors were encountered: