diff options
author | Nicholas Clark <nick@ccl4.org> | 2006-04-19 08:42:18 +0000 |
---|---|---|
committer | Nicholas Clark <nick@ccl4.org> | 2006-04-19 08:42:18 +0000 |
commit | cbf82dd00c19573e7e274a1d8dda9656bc6e259a (patch) | |
tree | 85a421e839c6a91506d7a9f972bf553b2cf43845 /sv.c | |
parent | 39cd7a593a348b713bd3e45241789bcc2a458c1a (diff) | |
download | perl-cbf82dd00c19573e7e274a1d8dda9656bc6e259a.tar.gz |
Calling cv_undef() on the CV created by newCONSTSUB() would leak like
a Jumblie's preferred maritime craft. To free CvFILE for this case,
take advantage of the 0 length prototype that will also be there,
and hang it from the prototype. To do this properly means changing
code to actually pay attention to SvCUR() on prototypes. It turns out
that we always know the length of the prototype string, so this may
be faster. Certainly, it's a memory saving (even ignoring the leak).
p4raw-id: //depot/perl@27896
Diffstat (limited to 'sv.c')
-rw-r--r-- | sv.c | 16 |
1 files changed, 9 insertions, 7 deletions
@@ -3309,8 +3309,9 @@ S_glob_assign_ref(pTHX_ SV *dstr, SV *sstr) { } } if (!intro) - cv_ckproto(cv, (GV*)dstr, - SvPOK(sref) ? SvPVX_const(sref) : NULL); + cv_ckproto_len(cv, (GV*)dstr, + SvPOK(sref) ? SvPVX_const(sref) : NULL, + SvPOK(sref) ? SvCUR(sref) : 0); } GvCVGEN(dstr) = 0; /* Switch off cacheness. */ GvASSUMECV_on(dstr); @@ -3898,7 +3899,7 @@ that pointer (e.g. ptr + 1) be used. If C<flags> & SV_SMAGIC is true, will call SvSETMAGIC. If C<flags> & SV_HAS_TRAILING_NUL is true, then C<ptr[len]> must be NUL, and the realloc -I<may> be skipped. (i.e. the buffer is actually at least 1 byte longer than +will be skipped. (i.e. the buffer is actually at least 1 byte longer than C<len>, and already meets the requirements for storing in C<SvPVX>) =cut @@ -3925,20 +3926,21 @@ Perl_sv_usepvn_flags(pTHX_ SV *sv, char *ptr, STRLEN len, U32 flags) allocate = (flags & SV_HAS_TRAILING_NUL) ? len + 1: PERL_STRLEN_ROUNDUP(len + 1); + if (flags & SV_HAS_TRAILING_NUL) { + /* It's long enough - do nothing. + Specfically Perl_newCONSTSUB is relying on this. */ + } else { #ifdef DEBUGGING - { /* Force a move to shake out bugs in callers. */ char *new_ptr = safemalloc(allocate); Copy(ptr, new_ptr, len, char); PoisonFree(ptr,len,char); Safefree(ptr); ptr = new_ptr; - } #else - if (!(flags & SV_HAS_TRAILING_NUL)) { ptr = saferealloc (ptr, allocate); - } #endif + } SvPV_set(sv, ptr); SvCUR_set(sv, len); SvLEN_set(sv, allocate); |