Change 27382 by [EMAIL PROTECTED] on 2006/03/05 19:07:12

        Perl_gv_name_set should not leak the old HEK. Allow the flag GV_ADD
        to simplify GV initialisation.

Affected files ...

... //depot/perl/gv.c#310 edit
... //depot/perl/gv.h#62 edit
... //depot/perl/sv.c#1182 edit

Differences ...

==== //depot/perl/gv.c#310 (text) ====
Index: perl/gv.c
--- perl/gv.c#309~27380~        2006-03-05 10:13:42.000000000 -0800
+++ perl/gv.c   2006-03-05 11:07:12.000000000 -0800
@@ -215,7 +215,7 @@
     GvSTASH(gv) = stash;
     if (stash)
        Perl_sv_add_backref(aTHX_ (SV*)stash, (SV*)gv);
-    gv_name_set(gv, name, len, 0);
+    gv_name_set(gv, name, len, GV_ADD);
     if (multi || doproto)              /* doproto means it _was_ mentioned */
        GvMULTI_on(gv);
     if (doproto) {                     /* Replicate part of newSUB here. */
@@ -2114,6 +2114,10 @@
     if (len > I32_MAX)
        Perl_croak(aTHX_ "panic: gv name too long (%"UVuf")", (UV) len);
 
+    if (!(flags & GV_ADD) && GvNAME_HEK(gv)) {
+       unshare_hek(GvNAME_HEK(gv));
+    }
+
     PERL_HASH(hash, name, len);
     GvNAME_HEK(gv) = name ? share_hek(name, len, hash) : 0;
 }

==== //depot/perl/gv.h#62 (text) ====
Index: perl/gv.h
--- perl/gv.h#61~27380~ 2006-03-05 10:13:42.000000000 -0800
+++ perl/gv.h   2006-03-05 11:07:12.000000000 -0800
@@ -187,7 +187,9 @@
 /*
  * symbol creation flags, for use in gv_fetchpv() and get_*v()
  */
-#define GV_ADD         0x01    /* add, if symbol not already there */
+#define GV_ADD         0x01    /* add, if symbol not already there
+                                  For gv_name_set, adding a HEK for the first
+                                  time, so don't try to free what's there.  */
 #define GV_ADDMULTI    0x02    /* add, pretending it has been added already */
 #define GV_ADDWARN     0x04    /* add, but warn if symbol wasn't already there 
*/
 #define GV_ADDINEVAL   0x08    /* add, as though we're doing so within an eval 
*/

==== //depot/perl/sv.c#1182 (text) ====
Index: perl/sv.c
--- perl/sv.c#1181~27379~       2006-03-05 09:47:23.000000000 -0800
+++ perl/sv.c   2006-03-05 11:07:12.000000000 -0800
@@ -3216,7 +3216,7 @@
        GvSTASH(dstr) = GvSTASH(sstr);
        if (GvSTASH(dstr))
            Perl_sv_add_backref(aTHX_ (SV*)GvSTASH(dstr), dstr);
-       gv_name_set((GV *)dstr, name, len, 0);
+       gv_name_set((GV *)dstr, name, len, GV_ADD);
        SvFAKE_on(dstr);        /* can coerce to non-glob */
     }
 
End of Patch.

Reply via email to