hv_free_ent: free SV as last action
authorDavid Mitchell <davem@iabyn.com>
Tue, 10 May 2011 12:52:48 +0000 (13:52 +0100)
committerDavid Mitchell <davem@iabyn.com>
Thu, 19 May 2011 13:49:43 +0000 (14:49 +0100)
Move the freeing of the SV from near the beginning to the end of
hv_free_ent(); i.e. free the HE before the SV. Ideally, this should cause
no change in behaviour, but will make using an iterative HV freeing
scheme easier.

hv.c

diff --git a/hv.c b/hv.c
index 20c3531..e78f84f 100644 (file)
--- a/hv.c
+++ b/hv.c
@@ -1470,7 +1470,6 @@ Perl_hv_free_ent(pTHX_ HV *hv, register HE *entry)
     val = HeVAL(entry);
     if (val && isGV(val) && isGV_with_GP(val) && GvCVu(val) && HvENAME(hv))
         mro_method_changed_in(hv);     /* deletion of method from stash */
-    SvREFCNT_dec(val);
     if (HeKLEN(entry) == HEf_SVKEY) {
        SvREFCNT_dec(HeKEY_sv(entry));
        Safefree(HeKEY_hek(entry));
@@ -1480,6 +1479,7 @@ Perl_hv_free_ent(pTHX_ HV *hv, register HE *entry)
     else
        Safefree(HeKEY_hek(entry));
     del_HE(entry);
+    SvREFCNT_dec(val);
 }