summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicholas Clark <nick@ccl4.org>2012-02-26 00:22:41 +0100
committerNicholas Clark <nick@ccl4.org>2012-03-13 17:39:44 +0100
commit5d3f331a5e4001d074f3f065e71e024cf59a8418 (patch)
tree347132d8448394aaccc20b80b731196948eb9d06
parent03e6b0f8aa279960cd8dd831f34ac3fea5310754 (diff)
downloadperl-smoke-me/linestr_sv.tar.gz
In S_parse_body(), don't "leak" linestr_sv until global destruction.smoke-me/linestr_sv
This commit ensures that linestr_sv is properly cleaned up, if allocated. The local variable linestr_sv was added by commit 009d90df4e17a415 in 2007, to replace use of PL_linestr in S_parse_body(). However, that commit didn't add any code to free linestr_sv at the end of S_parse_body(), meaning that the SV sticks around until global destruction. Subsequent code simplification possible by the removal of suidperl reveals that linestr_sv is only needed for the '-x' option, so it's safe to avoid allocating it up front. Additionally, during '-x' processing, Perl_sv_gets() will upgrade the target SV to SVt_PV and allocate the string buffer as needed, so there's no need to pre-upgrade or pre-allocate the SV in S_parse_body(). This slightly reduces the amount of code.
-rw-r--r--perl.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/perl.c b/perl.c
index e060948b7f..173789345d 100644
--- a/perl.c
+++ b/perl.c
@@ -1799,15 +1799,12 @@ S_parse_body(pTHX_ char **env, XSINIT_t xsinit)
#ifdef USE_SITECUSTOMIZE
bool minus_f = FALSE;
#endif
- SV *linestr_sv = newSV_type(SVt_PVIV);
+ SV *linestr_sv = NULL;
bool add_read_e_script = FALSE;
U32 lex_start_flags = 0;
PERL_SET_PHASE(PERL_PHASE_START);
- SvGROW(linestr_sv, 80);
- sv_setpvs(linestr_sv,"");
-
init_main_stash();
{
@@ -2103,6 +2100,8 @@ S_parse_body(pTHX_ char **env, XSINIT_t xsinit)
forbid_setid('x', suidscript);
/* Hence you can't get here if suidscript is true */
+ linestr_sv = newSV_type(SVt_PV);
+ lex_start_flags |= LEX_START_COPIED;
find_beginning(linestr_sv, rsfp);
if (cddir && PerlDir_chdir( (char *)cddir ) < 0)
Perl_croak(aTHX_ "Can't chdir to %s",cddir);
@@ -2231,6 +2230,9 @@ S_parse_body(pTHX_ char **env, XSINIT_t xsinit)
#endif
lex_start(linestr_sv, rsfp, lex_start_flags);
+ if(linestr_sv)
+ SvREFCNT_dec(linestr_sv);
+
PL_subname = newSVpvs("main");
if (add_read_e_script)