This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Fix two minor bugs with local glob assignment
[perl5.git] / sv.c
diff --git a/sv.c b/sv.c
index d8d0ff8..a2d0cbc 100644 (file)
--- a/sv.c
+++ b/sv.c
@@ -3741,7 +3741,7 @@ static void
 S_glob_assign_ref(pTHX_ SV *const dstr, SV *const sstr)
 {
     SV * const sref = SvRV(sstr);
-    SV *dref = NULL;
+    SV *dref;
     const int intro = GvINTRO(dstr);
     SV **location;
     U8 import_flag = 0;
@@ -3789,8 +3789,7 @@ S_glob_assign_ref(pTHX_ SV *const dstr, SV *const sstr)
            }
            SAVEGENERICSV(*location);
        }
-       else
-           dref = *location;
+       dref = *location;
        if (stype == SVt_PVCV && (*location != sref || GvCVGEN(dstr))) {
            CV* const cv = MUTABLE_CV(*location);
            if (cv) {
@@ -3907,7 +3906,7 @@ S_glob_assign_ref(pTHX_ SV *const dstr, SV *const sstr)
         }
        break;
     }
-    SvREFCNT_dec(dref);
+    if (!intro) SvREFCNT_dec(dref);
     if (SvTAINTED(sstr))
        SvTAINT(dstr);
     return;