PL_argvoutgv = gv_fetchpv("ARGVOUT",TRUE,SVt_PVIO);
if (io && (IoFLAGS(io) & IOf_ARGV) && (IoFLAGS(io) & IOf_START)) {
IoFLAGS(io) &= ~IOf_START;
- if (PL_inplace)
+ if (PL_inplace) {
+ if (!PL_argvout_stack)
+ PL_argvout_stack = newAV();
av_push(PL_argvout_stack, SvREFCNT_inc(PL_defoutgv));
+ }
}
if (PL_filemode & (S_ISUID|S_ISGID)) {
PerlIO_flush(IoIFP(GvIOn(PL_argvoutgv))); /* chmod must follow last write */
IoFLAGS(io) |= IOf_START;
if (PL_inplace) {
(void)do_close(PL_argvoutgv,FALSE);
- if (io && (IoFLAGS(io) & IOf_ARGV) && AvFILLp(PL_argvout_stack) >= 0) {
+ if (io && (IoFLAGS(io) & IOf_ARGV)
+ && PL_argvout_stack && AvFILLp(PL_argvout_stack) >= 0)
+ {
GV *oldout = (GV*)av_pop(PL_argvout_stack);
setdefout(oldout);
SvREFCNT_dec(oldout);
/* reset so print() ends up where we expect */
setdefout(Nullgv);
+ SvREFCNT_dec(PL_argvout_stack);
+ PL_argvout_stack = Nullav;
/* Prepare to destruct main symbol table. */
for (; argc > 0; argc--,argv++) {
av_push(GvAVn(PL_argvgv),newSVpv(argv[0],0));
}
- PL_argvout_stack = newAV();
}
if (PL_envgv = gv_fetchpv("ENV",TRUE, SVt_PVHV)) {
HV *hv;