summaryrefslogtreecommitdiff
path: root/gv.c
diff options
context:
space:
mode:
authorNicholas Clark <nick@ccl4.org>2006-03-05 19:07:12 +0000
committerNicholas Clark <nick@ccl4.org>2006-03-05 19:07:12 +0000
commitae8cc45f19735266b98e68ac96abd0c5050c140f (patch)
tree2a7bb46f4e08a63e1a40ec2c267201e32414866e /gv.c
parent4164be692ecdc110086abd011eb6e1c41f13ed34 (diff)
downloadperl-ae8cc45f19735266b98e68ac96abd0c5050c140f.tar.gz
Perl_gv_name_set should not leak the old HEK. Allow the flag GV_ADD
to simplify GV initialisation. p4raw-id: //depot/perl@27382
Diffstat (limited to 'gv.c')
-rw-r--r--gv.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/gv.c b/gv.c
index a458159d76..d02f741e44 100644
--- a/gv.c
+++ b/gv.c
@@ -215,7 +215,7 @@ Perl_gv_init(pTHX_ GV *gv, HV *stash, const char *name, STRLEN len, int multi)
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 @@ Perl_gv_name_set(pTHX_ GV *gv, const char *name, U32 len, U32 flags)
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;
}