summaryrefslogtreecommitdiff
path: root/sv.c
diff options
context:
space:
mode:
authorNicholas Clark <nick@ccl4.org>2006-04-19 08:42:18 +0000
committerNicholas Clark <nick@ccl4.org>2006-04-19 08:42:18 +0000
commitcbf82dd00c19573e7e274a1d8dda9656bc6e259a (patch)
tree85a421e839c6a91506d7a9f972bf553b2cf43845 /sv.c
parent39cd7a593a348b713bd3e45241789bcc2a458c1a (diff)
downloadperl-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.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/sv.c b/sv.c
index e9f47ddff4..df5a5564e6 100644
--- a/sv.c
+++ b/sv.c
@@ -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);