This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
skip readonly vars and unref references when doing a reset()
[perl5.git] / sv.c
diff --git a/sv.c b/sv.c
index ec224a3..ad38a87 100644 (file)
--- a/sv.c
+++ b/sv.c
@@ -3957,12 +3957,18 @@ sv_reset(register char *s, HV *stash)
        }
        for (i = 0; i <= (I32) HvMAX(stash); i++) {
            for (entry = HvARRAY(stash)[i];
-             entry;
-             entry = HeNEXT(entry)) {
+                entry;
+                entry = HeNEXT(entry))
+           {
                if (!todo[(U8)*HeKEY(entry)])
                    continue;
                gv = (GV*)HeVAL(entry);
                sv = GvSV(gv);
+               if (SvTHINKFIRST(sv)) {
+                   if (!SvREADONLY(sv) && SvROK(sv))
+                       sv_unref(sv);
+                   continue;
+               }
                (void)SvOK_off(sv);
                if (SvTYPE(sv) >= SVt_PV) {
                    SvCUR_set(sv, 0);