[perl #128313] Fix leak in perl 5.24 with strict and regex posix char classes
authorYves Orton <[email protected]>
Wed, 8 Jun 2016 16:42:30 +0000 (18:42 +0200)
committerYves Orton <[email protected]>
Wed, 8 Jun 2016 16:42:33 +0000 (18:42 +0200)
This patch is a refinement of one written by Dan Collins.

Any thanks for this patch should go to him.

regcomp.c

index 0b1e606..8562b8f 100644 (file)
--- a/regcomp.c
+++ b/regcomp.c
@@ -13764,7 +13764,7 @@ S_populate_ANYOF_from_invlist(pTHX_ regnode *node, SV** invlist_ptr)
  * routine. q.v. */
 #define ADD_POSIX_WARNING(p, text)  STMT_START {                            \
         if (posix_warnings) {                                               \
-            if (! warn_text) warn_text = newAV();                           \
+            if (! warn_text) warn_text = (AV *) sv_2mortal((SV *) newAV()); \
             av_push(warn_text, Perl_newSVpvf(aTHX_                          \
                                              WARNING_PREFIX                 \
                                              text                           \
@@ -14530,13 +14530,9 @@ S_handle_possible_posix(pTHX_ RExC_state_t *pRExC_state,
             }
 
             if (warn_text) {
-                if (posix_warnings) {
-                    /* mortalize to avoid a leak with FATAL warnings */
-                    *posix_warnings = (AV *) sv_2mortal((SV *) warn_text);
-                }
-                else {
-                    SvREFCNT_dec_NN(warn_text);
-                }
+                /* warn_text should only be true if posix_warnings is true */
+                assert(posix_warnings);
+                *posix_warnings = warn_text;
             }
         }
         else if (class_number != OOB_NAMEDCLASS) {