Skip to content

Commit

Permalink
Stop unterminated here-docs from leaking memory
Browse files Browse the repository at this point in the history
  • Loading branch information
Father Chrysostomos committed Aug 28, 2012
1 parent 83944c0 commit 2d85e41
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions MANIFEST
Expand Up @@ -5370,6 +5370,7 @@ t/op/sub_lval.t See if lvalue subroutines work
t/op/substr.t See if substr works
t/op/substr_thr.t See if substr works in another thread
t/op/sub.t See if subroutines work
t/op/svleak.pl Test file for svleak.t
t/op/svleak.t See if stuff leaks SVs
t/op/switch.t See if switches (given/when) work
t/op/symbolcache.t See if undef/delete works on stashes with functions
Expand Down
1 change: 1 addition & 0 deletions t/op/svleak.pl
@@ -0,0 +1 @@
<<END
11 changes: 10 additions & 1 deletion t/op/svleak.t
Expand Up @@ -15,7 +15,7 @@ BEGIN {

use Config;

plan tests => 22;
plan tests => 25;

# run some code N times. If the number of SVs at the end of loop N is
# greater than (N-1)*delta at the end of loop 1, we've got a leak
Expand Down Expand Up @@ -172,3 +172,12 @@ SKIP: {
leak(2, 0, sub { eval q{ my $x = "x"; "abc" =~ /$x/ for 1..5 } }, '#114356');
}

SKIP: {
skip "disabled under -Dmad (eval leaks)" if $Config{mad};
leak(2, 0, sub { eval '"${<<END}"
' }, 'unterminated here-doc in quotes in multiline eval');
leak(2, 0, sub { eval '"${<<END
}"' }, 'unterminated here-doc in multiline quotes in eval');
leak(2, 0, sub { eval { do './op/svleak.pl' } },
'unterminated here-doc in file');
}
6 changes: 6 additions & 0 deletions toke.c
Expand Up @@ -9681,6 +9681,8 @@ S_scan_heredoc(pTHX_ register char *s)
++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);
}
Expand All @@ -9705,6 +9707,8 @@ S_scan_heredoc(pTHX_ register char *s)
++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);
}
Expand Down Expand Up @@ -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')) {
SvREFCNT_dec(herewas);
SvREFCNT_dec(tmpstr);
CopLINE_set(PL_curcop, (line_t)PL_multi_start);
missingterm(PL_tokenbuf + 1);
}
Expand Down

0 comments on commit 2d85e41

Please sign in to comment.