This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Stop unterminated here-docs from leaking memory
[perl5.git] / toke.c
diff --git a/toke.c b/toke.c
index fa8f5e7..c607071 100644 (file)
--- a/toke.c
+++ b/toke.c
@@ -9681,6 +9681,8 @@ S_scan_heredoc(pTHX_ register char *s)
                ++PL_parser->herelines;
        }
        if (s >= bufend) {
                ++PL_parser->herelines;
        }
        if (s >= bufend) {
+           SvREFCNT_dec(herewas);
+           SvREFCNT_dec(tmpstr);
            CopLINE_set(PL_curcop, (line_t)PL_multi_start);
            missingterm(PL_tokenbuf + 1);
        }
            CopLINE_set(PL_curcop, (line_t)PL_multi_start);
            missingterm(PL_tokenbuf + 1);
        }
@@ -9705,6 +9707,8 @@ S_scan_heredoc(pTHX_ register char *s)
                ++PL_parser->herelines;
        }
        if (s >= PL_bufend) {
                ++PL_parser->herelines;
        }
        if (s >= PL_bufend) {
+           SvREFCNT_dec(herewas);
+           SvREFCNT_dec(tmpstr);
            CopLINE_set(PL_curcop, (line_t)PL_multi_start);
            missingterm(PL_tokenbuf + 1);
        }
            CopLINE_set(PL_curcop, (line_t)PL_multi_start);
            missingterm(PL_tokenbuf + 1);
        }
@@ -9759,6 +9763,8 @@ S_scan_heredoc(pTHX_ register char *s)
        CopLINE_set(PL_curcop, PL_multi_start + PL_parser->herelines + 1);
        if (!lex_next_chunk(LEX_NO_TERM)
         && (!SvCUR(tmpstr) || SvEND(tmpstr)[-1] != '\n')) {
        CopLINE_set(PL_curcop, PL_multi_start + PL_parser->herelines + 1);
        if (!lex_next_chunk(LEX_NO_TERM)
         && (!SvCUR(tmpstr) || SvEND(tmpstr)[-1] != '\n')) {
+           SvREFCNT_dec(herewas);
+           SvREFCNT_dec(tmpstr);
            CopLINE_set(PL_curcop, (line_t)PL_multi_start);
            missingterm(PL_tokenbuf + 1);
        }
            CopLINE_set(PL_curcop, (line_t)PL_multi_start);
            missingterm(PL_tokenbuf + 1);
        }