diff options
author | David Mitchell <davem@iabyn.com> | 2010-11-17 16:29:04 +0000 |
---|---|---|
committer | David Mitchell <davem@iabyn.com> | 2010-11-26 16:01:34 +0000 |
commit | 8995e67d43b457d0463f0581e10b390bc378c894 (patch) | |
tree | 3ed18b1421df68b44e5483897a7b875b6697ada1 /perlio.c | |
parent | 16865ff7e97c2532fd2001d68cf18909acb0d838 (diff) | |
download | perl-8995e67d43b457d0463f0581e10b390bc378c894.tar.gz |
add PerlIO_init_table() to initialise PL_perio
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.
Diffstat (limited to 'perlio.c')
-rw-r--r-- | perlio.c | 14 |
1 files changed, 12 insertions, 2 deletions
@@ -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) { @@ -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; @@ -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); |