This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
SAVEt_CLEARSV: only clear-in-place if RC==1
authorDavid Mitchell <davem@iabyn.com>
Fri, 28 Feb 2014 19:25:51 +0000 (19:25 +0000)
committerDavid Mitchell <davem@iabyn.com>
Fri, 28 Feb 2014 19:39:23 +0000 (19:39 +0000)
Currently it takes the 'clear-in-place' branch on lexical vars if
the ref count is <= 1. However, RC < 1 is a "should never happen"
condition, so rather than keeping that damaged var, take the other branch,
which will call SvREFCNT_dec() on it, which will Do the Right Thing
(like emitting a warning).

scope.c

diff --git a/scope.c b/scope.c
index d326220..4c4f527 100644 (file)
--- a/scope.c
+++ b/scope.c
@@ -1039,7 +1039,7 @@ Perl_leave_scope(pTHX_ I32 base)
                 assert(SvPADMY(sv));
 
                 /* Can clear pad variable in place? */
-                if (SvREFCNT(sv) <= 1 && !SvOBJECT(sv)) {
+                if (SvREFCNT(sv) == 1 && !SvOBJECT(sv)) {
 
                     /* these flags are the union of all the relevant flags
                      * in the individual conditions within */