This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
fix CvFILE() leak in Perl_newATTRSUB_x()
authorDavid Mitchell <davem@iabyn.com>
Thu, 7 Mar 2019 10:23:04 +0000 (10:23 +0000)
committerDavid Mitchell <davem@iabyn.com>
Thu, 7 Mar 2019 11:21:26 +0000 (11:21 +0000)
When overwriting cv with the contents of PL_compcv, it was checking the
CvDYNFILE(cv) flag (to see if CvFILE(cv) needed freeing) *after*
overwriting cv's flags with PL_compcv's flag.

op.c

diff --git a/op.c b/op.c
index ffed2bd..40bc2ef 100644 (file)
--- a/op.c
+++ b/op.c
@@ -10201,6 +10201,7 @@ Perl_newATTRSUB_x(pTHX_ I32 floor, OP *o, OP *proto, OP *attrs,
     if (cv) {                          /* must reuse cv if autoloaded */
        /* transfer PL_compcv to cv */
        if (block) {
+            bool free_file = CvFILE(cv) && CvDYNFILE(cv);
            cv_flags_t existing_builtin_attrs = CvFLAGS(cv) & CVf_BUILTIN_ATTRS;
            PADLIST *const temp_av = CvPADLIST(cv);
            CV *const temp_cv = CvOUTSIDE(cv);
@@ -10238,7 +10239,7 @@ Perl_newATTRSUB_x(pTHX_ I32 floor, OP *o, OP *proto, OP *attrs,
            CvFLAGS(PL_compcv) &= ~(CVf_SLABBED|CVf_WEAKOUTSIDE);
            CvFLAGS(PL_compcv) |= other_flags;
 
-           if (CvFILE(cv) && CvDYNFILE(cv)) {
+           if (free_file) {
                Safefree(CvFILE(cv));
             }
            CvFILE_set_from_cop(cv, PL_curcop);