This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
fix a leak with indented heredocs
authorDavid Mitchell <davem@iabyn.com>
Mon, 25 Mar 2019 20:13:30 +0000 (20:13 +0000)
committerDavid Mitchell <davem@iabyn.com>
Mon, 25 Mar 2019 20:32:21 +0000 (20:32 +0000)
With something like

   |print <<~EOF;
   | some data
   |   EOF

it croaks (as it should) with "Indentation ... doesn't match delimiter",
but in that case it leaks the recently malloc()d 'indent' buffer.

The fix is simple.  I've also fixed by code inspection where the code
does 'goto interminable', although I didn't try to reproduce the conditions
where the goto might occur.

toke.c

diff --git a/toke.c b/toke.c
index 4066c6b..8b0c655 100644 (file)
--- a/toke.c
+++ b/toke.c
@@ -10407,6 +10407,7 @@ S_scan_heredoc(pTHX_ char *s)
            /* Line doesn't begin with our indentation? Croak */
            }
             else {
+                Safefree(indent);
                Perl_croak(aTHX_
                    "Indentation on line %d of here-doc doesn't match delimiter",
                    (int)linecount
@@ -10434,6 +10435,8 @@ S_scan_heredoc(pTHX_ char *s)
     return s;
 
   interminable:
+    if (indent)
+       Safefree(indent);
     SvREFCNT_dec(tmpstr);
     CopLINE_set(PL_curcop, origline);
     missingterm(PL_tokenbuf + 1, sizeof(PL_tokenbuf) - 1);