This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
op.c:leave_scope: use mg_free before sv_force_normal
[perl5.git] / scope.c
diff --git a/scope.c b/scope.c
index 3c9b15c..38eea2f 100644 (file)
--- a/scope.c
+++ b/scope.c
@@ -1046,9 +1046,6 @@ Perl_leave_scope(pTHX_ I32 base)
                     if (SvPADMY(sv) && !SvFAKE(sv))
                         SvREADONLY_off(sv);
 
-                    if (SvTHINKFIRST(sv))
-                        sv_force_normal_flags(sv, SV_IMMEDIATE_UNREF
-                                                 |SV_COW_DROP_PV);
                     if (SvTYPE(sv) == SVt_PVHV)
                         Perl_hv_kill_backrefs(aTHX_ MUTABLE_HV(sv));
                     if (SvMAGICAL(sv))
@@ -1057,6 +1054,9 @@ Perl_leave_scope(pTHX_ I32 base)
                       if (SvTYPE(sv) != SVt_PVCV)
                         mg_free(sv);
                     }
+                    if (SvTHINKFIRST(sv))
+                        sv_force_normal_flags(sv, SV_IMMEDIATE_UNREF
+                                                 |SV_COW_DROP_PV);
 
                     switch (SvTYPE(sv)) {
                     case SVt_NULL: