HE *didstore;
sv = *relem ? *relem : &PL_sv_no;
relem++;
- tmpstr = newSV(0);
+ tmpstr = sv_newmortal();
if (*relem)
sv_setsv(tmpstr,*relem); /* value */
relem++;
}
}
didstore = hv_store_ent(hash,sv,tmpstr,0);
+ if (didstore) SvREFCNT_inc_simple_void_NN(tmpstr);
if (magic) {
if (SvSMAGICAL(tmpstr))
mg_set(tmpstr);
- if (!didstore)
- sv_2mortal(tmpstr);
}
TAINT_NOT;
}
use Config;
-plan tests => 29;
+plan tests => 30;
# 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
each %$h;
undef $h;
}, 'tied hash iteration does not leak');
+
+# Hash assignment was leaking when assigning explosive scalars
+package sty {
+ sub TIESCALAR { bless [] }
+ sub FETCH { die }
+}
+leak(2, 0, sub {
+ tie my $x, sty;
+ eval {%a = ($x, 0)}; # key
+ eval {%a = (0, $x)}; # value
+ eval {%a = ($x,$x)}; # both
+}, 'hash assignment does not leak');
+