This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
regcomp.c: Fix leak
authorKarl Williamson <khw@cpan.org>
Sat, 25 Apr 2020 15:28:51 +0000 (09:28 -0600)
committerSawyer X <xsawyerx@cpan.org>
Sun, 24 May 2020 19:02:49 +0000 (22:02 +0300)
This leak is the result of my misplacing the frees in an inner block
which isn't always executed after space is allocated; instead of the
next outer where the free will get done.

This fixes # 17729

regcomp.c

index 9b472c9..4e9f322 100644 (file)
--- a/regcomp.c
+++ b/regcomp.c
@@ -15173,9 +15173,6 @@ S_regatom(pTHX_ RExC_state_t *pRExC_state, I32 *flagp, U32 depth)
                         * have to map that back to the original */
                         if (need_to_fold_loc) {
                             upper_fill = loc_correspondence[s - s_start];
-                            Safefree(locfold_buf);
-                            Safefree(loc_correspondence);
-
                             if (upper_fill == 0) {
                                 FAIL2("panic: loc_correspondence[%d] is 0",
                                       (int) (s - s_start));
@@ -15186,10 +15183,6 @@ S_regatom(pTHX_ RExC_state_t *pRExC_state, I32 *flagp, U32 depth)
                         }
                         goto reparse;
                     }
-                    else if (need_to_fold_loc) {
-                        Safefree(locfold_buf);
-                        Safefree(loc_correspondence);
-                    }
 
                     /* Here the node consists entirely of non-final multi-char
                      * folds.  (Likely it is all 'f's or all 's's.)  There's no
@@ -15197,6 +15190,11 @@ S_regatom(pTHX_ RExC_state_t *pRExC_state, I32 *flagp, U32 depth)
                      * whole thing */
                     len = old_s - s0;
                 }
+
+                if (need_to_fold_loc) {
+                    Safefree(locfold_buf);
+                    Safefree(loc_correspondence);
+                }
            }   /* End of verifying node ends with an appropriate char */
 
             /* We need to start the next node at the character that didn't fit