From a83eb62d86a48741cbe2decf2bd99ef5292d1c02 Mon Sep 17 00:00:00 2001 From: David Mitchell 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.28.1 from e40cca748f05c81e1929ed625407afbe7c79d4dd/ Signed-off-by: Petr Písař --- toke.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/toke.c b/toke.c index 4747ef5..240fd49 100644 --- a/toke.c +++ b/toke.c @@ -10365,6 +10365,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 @@ -10388,6 +10389,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); -- 2.20.1