Skip to content

Commit

Permalink
Move PERL_INTERNAL_RAND_SEED set-up after init_stacks().
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
craigberry committed Oct 7, 2017
1 parent 1195d90 commit e04fc1a
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions perl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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();
Expand Down

0 comments on commit e04fc1a

Please sign in to comment.