[perl #109762] Stop !$^V from leaking
authorFather Chrysostomos <sprout@cpan.org>
Sat, 4 Feb 2012 05:55:31 +0000 (21:55 -0800)
committerFather Chrysostomos <sprout@cpan.org>
Sat, 4 Feb 2012 06:26:29 +0000 (22:26 -0800)
by mortalising the temporary SVs.

t/op/svleak.t
universal.c

index 4eee3c8..df10953 100644 (file)
@@ -13,7 +13,7 @@ BEGIN {
        or skip_all("XS::APItest not available");
 }
 
-plan tests => 20;
+plan tests => 21;
 
 # 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
@@ -158,3 +158,5 @@ leak(2, 0,
         my $tag = $+{tag};
     }, "named regexp captures");
 }
+
+leak(2,0,sub { !$^V }, '[perl #109762] version object in boolean context');
index 463651b..b3c7015 100644 (file)
@@ -652,7 +652,13 @@ XS(XS_version_boolean)
     SP -= items;
     if (sv_isobject(ST(0)) && sv_derived_from(ST(0), "version")) {
        SV * const lobj = SvRV(ST(0));
-       SV * const rs = newSViv( vcmp(lobj,new_version(newSVpvs("0"))) );
+       SV * const rs =
+           newSViv( vcmp(lobj,
+                         sv_2mortal(new_version(
+                                       sv_2mortal(newSVpvs("0"))
+                                   ))
+                        )
+                  );
        mPUSHs(rs);
        PUTBACK;
        return;