Blob Blame History Raw
From 706bf039995c9a267230ba04fc6bc40c370f63ba Mon Sep 17 00:00:00 2001
From: David Mitchell <davem@iabyn.com>
Date: Mon, 25 Mar 2019 20:13:30 +0000
Subject: [PATCH] fix a leak with indented heredocs
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

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.

Petr Písař: Ported to 5.26.3 from
e40cca748f05c81e1929ed625407afbe7c79d4dd.

Signed-off-by: Petr Písař <ppisar@redhat.com>
---
 toke.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/toke.c b/toke.c
index 49eaa80..9055d00 100644
--- a/toke.c
+++ b/toke.c
@@ -10258,6 +10258,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
@@ -10281,6 +10282,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);
-- 
2.20.1