This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Change 28063 should have removed the call to savepvn() from Perl_newCONSTSUB()
authorNicholas Clark <nick@ccl4.org>
Wed, 21 Jan 2009 11:25:42 +0000 (11:25 +0000)
committerNicholas Clark <nick@ccl4.org>
Wed, 21 Jan 2009 11:43:20 +0000 (11:43 +0000)
completely when it moved the allocation logic inside Perl_newXS_flags(). Whilst
Rafael's fix in 29107 correctly plugged my leak, this commit is the actual
correction. (Commits 77004dee2553ce034a8a58b2b2849e3656df46c3 and
c3db7d9213b09a5852dab00368488f63a7625b9e respectively)

op.c

diff --git a/op.c b/op.c
index d80aa95..444ee3b 100644 (file)
--- a/op.c
+++ b/op.c
@@ -5959,14 +5959,11 @@ Perl_newCONSTSUB(pTHX_ HV *stash, const char *name, SV *sv)
     dVAR;
     CV* cv;
 #ifdef USE_ITHREADS
-    const char *const temp_p = CopFILE(PL_curcop);
-    const STRLEN len = temp_p ? strlen(temp_p) : 0;
+    const char *const file = CopFILE(PL_curcop);
 #else
     SV *const temp_sv = CopFILESV(PL_curcop);
-    STRLEN len;
-    const char *const temp_p = temp_sv ? SvPV_const(temp_sv, len) : NULL;
+    const char *const file = temp_sv ? SvPV_const_nolen(temp_sv) : NULL;
 #endif
-    char *const file = savepvn(temp_p, temp_p ? len : 0);
 
     ENTER;
 
@@ -5994,10 +5991,10 @@ Perl_newCONSTSUB(pTHX_ HV *stash, const char *name, SV *sv)
        and so doesn't get free()d.  (It's expected to be from the C pre-
        processor __FILE__ directive). But we need a dynamically allocated one,
        and we need it to get freed.  */
-    cv = newXS_flags(name, const_sv_xsub, file, "", XS_DYNAMIC_FILENAME);
+    cv = newXS_flags(name, const_sv_xsub, file ? file : "", "",
+                    XS_DYNAMIC_FILENAME);
     CvXSUBANY(cv).any_ptr = sv;
     CvCONST_on(cv);
-    Safefree(file);
 
 #ifdef USE_ITHREADS
     if (stash)