summaryrefslogtreecommitdiff
path: root/perl.c
diff options
context:
space:
mode:
authorNicholas Clark <nick@ccl4.org>2012-02-24 16:13:29 +0100
committerNicholas Clark <nick@ccl4.org>2012-02-27 11:31:48 +0100
commit8760603268ed1d1d91135ea121b222b4ee123e6e (patch)
treed3ec683528e795abd85a4002c5e3ecb4debe28f6 /perl.c
parenta7c8193001a8197325b9fbb189ee567db3ca6219 (diff)
downloadperl-8760603268ed1d1d91135ea121b222b4ee123e6e.tar.gz
The parser should always close the file handle that it opened.
Previously it would leave the file handle open if it was (equal to) stdin, on the assumption that this must have been because no script name was supplied on the interpreter command line, so the interpreter was defaulting to reading the script from standard input. However, if the program has closed STDIN, then the next file handle opened (for any reason) will have file descriptor 0. So in this situation, the handle that require opened to read the module would be mistaken for the above situation and left open. Effectively, this leaked a file handle. This is now fixed, by explicitly tracking from parser creation time whether it should keep the file handle open, and only setting this flag when defaulting to reading the main program from standard input. This resolves RT #37033.
Diffstat (limited to 'perl.c')
-rw-r--r--perl.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/perl.c b/perl.c
index 3610780ca3..104cac7c8a 100644
--- a/perl.c
+++ b/perl.c
@@ -1803,6 +1803,7 @@ S_parse_body(pTHX_ char **env, XSINIT_t xsinit)
#endif
SV *linestr_sv = newSV_type(SVt_PVIV);
bool add_read_e_script = FALSE;
+ U32 lex_start_flags = 0;
PERL_SET_PHASE(PERL_PHASE_START);
@@ -2076,6 +2077,7 @@ S_parse_body(pTHX_ char **env, XSINIT_t xsinit)
rsfp = open_script(scriptname, dosearch, &suidscript);
if (!rsfp) {
rsfp = PerlIO_stdin();
+ lex_start_flags = LEX_DONT_CLOSE_RSFP;
}
validate_suid(validarg, scriptname, fdscript, suidscript,
@@ -2231,7 +2233,7 @@ S_parse_body(pTHX_ char **env, XSINIT_t xsinit)
}
#endif
- lex_start(linestr_sv, rsfp, 0);
+ lex_start(linestr_sv, rsfp, lex_start_flags);
PL_subname = newSVpvs("main");
if (add_read_e_script)