From e04fc1aa1cb8f08ee6e04f5c80e645cad2b3c75a Mon Sep 17 00:00:00 2001 From: "Craig A. Berry" Date: Sat, 7 Oct 2017 13:31:29 -0500 Subject: [PATCH] Move PERL_INTERNAL_RAND_SEED set-up after init_stacks(). This code may be calling things that put SVs on the stack, so we should have a stack before doing so. That risk might be theoretical on most platforms, but on VMS, the getenv implementation mortalizes an SV when doing lookups. This meant that on a DEBUGGING build with PERL_DESTRUCT_LEVEL set, any code or no code at all would warn like so: $ perl -e ";" Attempt to free temp prematurely: SV 0x845718 during global destruction. Scalars leaked: 1 Getting the stack initialized first fixes that. --- perl.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/perl.c b/perl.c index fd100cc64a0d..dc77e49f8b06 100644 --- a/perl.c +++ b/perl.c @@ -261,6 +261,22 @@ perl_construct(pTHXx) init_constants(); + SvREADONLY_on(&PL_sv_placeholder); + SvREFCNT(&PL_sv_placeholder) = SvREFCNT_IMMORTAL; + + PL_sighandlerp = (Sighandler_t) Perl_sighandler; +#ifdef PERL_USES_PL_PIDSTATUS + PL_pidstatus = newHV(); +#endif + + PL_rs = newSVpvs("\n"); + + init_stacks(); + +/* The PERL_INTERNAL_RAND_SEED set-up must be after init_stacks because it calls + * things that may put SVs on the stack. + */ + #ifdef NO_PERL_INTERNAL_RAND_SEED Perl_drand48_init_r(&PL_internal_random_state, seed()); #else @@ -277,18 +293,6 @@ perl_construct(pTHXx) } #endif - SvREADONLY_on(&PL_sv_placeholder); - SvREFCNT(&PL_sv_placeholder) = SvREFCNT_IMMORTAL; - - PL_sighandlerp = (Sighandler_t) Perl_sighandler; -#ifdef PERL_USES_PL_PIDSTATUS - PL_pidstatus = newHV(); -#endif - - PL_rs = newSVpvs("\n"); - - init_stacks(); - init_ids(); S_fixup_platform_bugs();