while (relem <= lastrelem) { /* gobble up all the rest */
SV **didstore;
assert(*relem);
- sv = newSV(0);
+ sv = sv_newmortal();
sv_setsv(sv, *relem);
*(relem++) = sv;
didstore = av_store(ary,i++,sv);
+ if (didstore) SvREFCNT_inc_simple_void_NN(sv);
if (magic) {
if (SvSMAGICAL(sv))
mg_set(sv);
- if (!didstore)
- sv_2mortal(sv);
}
TAINT_NOT;
}
{
local $TODO = "sort should make sure elements are not freed in the sort block";
- eval { @nomodify_x=(1..8); our @copy = sort { @nomodify_x = (0) } (@nomodify_x, 3); };
+ eval { @nomodify_x=(1..8);
+ our @copy = sort { undef @nomodify_x; 1 } (@nomodify_x, 3); };
is($@, "");
}
use Config;
-plan tests => 30;
+plan tests => 31;
# run some code N times. If the number of SVs at the end of loop N is
# greater than (N-1)*delta at the end of loop 1, we've got a leak
undef $h;
}, 'tied hash iteration does not leak');
-# Hash assignment was leaking when assigning explosive scalars
+# List assignment was leaking when assigning explosive scalars to
+# aggregates.
package sty {
sub TIESCALAR { bless [] }
sub FETCH { die }
eval {%a = (0, $x)}; # value
eval {%a = ($x,$x)}; # both
}, 'hash assignment does not leak');
+leak(2, 0, sub {
+ tie my $x, sty;
+ eval {@a = ($x)};
+}, 'array assignment does not leak');