Skip to content

Commit

Permalink
add PerlIO_init_table() to initialise PL_perio
Browse files Browse the repository at this point in the history
Previously, the PL_perio table was initialised by calling PerlIO_allocate,
and throwing away the result. Since a slot with a null ->next was regarded
as freed, the next call to PerlIO_allocate would reuse that slot, which is
important, as STDIN etc are expected to occupy slots 1,2,3.

Once reference counting of the slots is introduced, however, the first
slot will leak, and STDIN etc will be assigned to the wrong slots. So do it
properly now.
  • Loading branch information
iabyn committed Nov 26, 2010
1 parent 16865ff commit 8995e67
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions perlio.c
Expand Up @@ -558,6 +558,16 @@ PerlIO_verify_head(pTHX_ PerlIO *f)
*/
#define PERLIO_TABLE_SIZE 64

static void
PerlIO_init_table(pTHX)
{
if (PL_perlio)
return;
Newxz(PL_perlio, PERLIO_TABLE_SIZE, PerlIOl);
}



PerlIO *
PerlIO_allocate(pTHX)
{
Expand Down Expand Up @@ -706,7 +716,7 @@ PerlIO_clone(pTHX_ PerlInterpreter *proto, CLONE_PARAMS *param)
PL_perlio = NULL;
PL_known_layers = PerlIO_clone_list(aTHX_ proto->Iknown_layers, param);
PL_def_layerlist = PerlIO_clone_list(aTHX_ proto->Idef_layerlist, param);
PerlIO_allocate(aTHX); /* root slot is never used */
PerlIO_init_table(aTHX);
PerlIO_debug("Clone %p from %p\n",(void*)aTHX,(void*)proto);
while ((f = *table)) {
int i;
Expand Down Expand Up @@ -1233,7 +1243,7 @@ PerlIO_stdstreams(pTHX)
{
dVAR;
if (!PL_perlio) {
PerlIO_allocate(aTHX);
PerlIO_init_table(aTHX);
PerlIO_fdopen(0, "Ir" PERLIO_STDTEXT);
PerlIO_fdopen(1, "Iw" PERLIO_STDTEXT);
PerlIO_fdopen(2, "Iw" PERLIO_STDTEXT);
Expand Down

0 comments on commit 8995e67

Please sign in to comment.