summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFather Chrysostomos <sprout@cpan.org>2010-11-02 20:06:08 -0700
committerFather Chrysostomos <sprout@cpan.org>2010-11-02 21:32:34 -0700
commit4eedab498fc909c786cceea9a6f3a70fa4433f9b (patch)
treefb6b39f16dd28ea5e169514fc8d9e20bc86234d3
parent8db9069ca0bb3b524c2f656356fc526984285a58 (diff)
downloadperl-4eedab498fc909c786cceea9a6f3a70fa4433f9b.tar.gz
s///r leaks like a sieve
-rw-r--r--pp_hot.c2
-rw-r--r--t/re/subst.t7
2 files changed, 7 insertions, 2 deletions
diff --git a/pp_hot.c b/pp_hot.c
index 7f80fa5296..a3fea5ca7a 100644
--- a/pp_hot.c
+++ b/pp_hot.c
@@ -2120,7 +2120,7 @@ PP(pp_subst)
/* In non-destructive replacement mode, duplicate target scalar so it
* remains unchanged. */
if (rpm->op_pmflags & PMf_NONDESTRUCT)
- TARG = newSVsv(TARG);
+ TARG = sv_2mortal(newSVsv(TARG));
#ifdef PERL_OLD_COPY_ON_WRITE
/* Awooga. Awooga. "bool" types that are actually char are dangerous,
diff --git a/t/re/subst.t b/t/re/subst.t
index cb43510d31..8ea53a2f4a 100644
--- a/t/re/subst.t
+++ b/t/re/subst.t
@@ -7,7 +7,7 @@ BEGIN {
}
require './test.pl';
-plan( tests => 172 );
+plan( tests => 174 );
# Stolen from re/ReTest.pl. Can't just use the file since it doesn't support
# like() and it conflicts with test.pl
@@ -88,6 +88,11 @@ ok( defined tied($m), 's///r magic isn\'t lost' );
$b = $m =~ s/xxx/yyy/r;
ok( ! defined tied($b), 's///r magic isn\'t contagious' );
+my $ref = \("aaa" =~ s/aaa/bbb/r);
+is (Internals::SvREFCNT($$ref), 1, 's///r does not leak');
+$ref = \("aaa" =~ s/aaa/bbb/rg);
+is (Internals::SvREFCNT($$ref), 1, 's///rg does not leak');
+
$x = 'foo';
$_ = "x";
s/x/\$x/;