use sv_2mortal rather than doing SvREFCNT_dec manually
Graham Knop [Thu, 25 Jan 2018 14:07:57 +0000 (15:07 +0100)]
Name.xs

diff --git a/Name.xs b/Name.xs
index 5f7c06e..43bd5bd 100644 (file)
--- a/Name.xs
+++ b/Name.xs
@@ -114,7 +114,7 @@ subname(name, sub)
                        STRLEN length = end - nameptr + quotes_seen - (*end == '\'' ? 1 : 0);
                        char* left;
                        int i, j;
-                       tmp = newSV(length);
+                       tmp = sv_2mortal(newSV(length));
                        left = SvPVX(tmp);
                        for (i = 0, j = 0; j < end - nameptr; ++i, ++j) {
                                if (nameptr[j] == '\'') {
@@ -126,7 +126,6 @@ subname(name, sub)
                                }
                        }
                        stash = gv_stashpvn(left, length, GV_ADD | utf8flag);
-                       SvREFCNT_dec(tmp);
                }
                else
                        stash = gv_stashpvn(nameptr, end - nameptr, GV_ADD | utf8flag);
@@ -141,22 +140,19 @@ subname(name, sub)
 
                GV* oldgv = CvGV(cv);
                HV* oldhv = GvSTASH(oldgv);
-               SV* old_full_name = newSVpvn_flags(HvNAME(oldhv), HvNAMELEN_get(oldhv), HvNAMEUTF8(oldhv) ? SVf_UTF8 : 0);
+               SV* old_full_name = sv_2mortal(newSVpvn_flags(HvNAME(oldhv), HvNAMELEN_get(oldhv), HvNAMEUTF8(oldhv) ? SVf_UTF8 : 0));
                sv_catpvn(old_full_name, "::", 2);
                sv_catpvn_flags(old_full_name, GvNAME(oldgv), GvNAMELEN(oldgv), GvNAMEUTF8(oldgv) ? SV_CATUTF8 : SV_CATBYTES);
 
                old_data = hv_fetch_ent(DBsub, old_full_name, 0, 0);
 
-               SvREFCNT_dec(old_full_name);
-
                if (old_data && HeVAL(old_data)) {
-                       SV* new_full_name = newSVpvn_flags(HvNAME(stash), HvNAMELEN_get(stash), HvNAMEUTF8(stash) ? SVf_UTF8 : 0);
+                       SV* new_full_name = sv_2mortal(newSVpvn_flags(HvNAME(stash), HvNAMELEN_get(stash), HvNAMEUTF8(stash) ? SVf_UTF8 : 0));
                        sv_catpvn(new_full_name, "::", 2);
                        sv_catpvn_flags(new_full_name, nameptr, s - nameptr, utf8flag ? SV_CATUTF8 : SV_CATBYTES);
                        SvREFCNT_inc(HeVAL(old_data));
                        if (hv_store_ent(DBsub, new_full_name, HeVAL(old_data), 0) != NULL)
                                SvREFCNT_inc(HeVAL(old_data));
-                       SvREFCNT_dec(new_full_name);
                }
        }