From cb1ad50e615d49477a97593b9e0569e7167a258e Mon Sep 17 00:00:00 2001 From: Father Chrysostomos Date: Sat, 8 Jun 2013 00:11:23 -0700 Subject: [PATCH] [perl #117941] eval crashes when current stash is freed --- pp_ctl.c | 4 +++- t/op/eval.t | 7 ++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/pp_ctl.c b/pp_ctl.c index b3e813e..7a2ba07 100644 --- a/pp_ctl.c +++ b/pp_ctl.c @@ -3402,7 +3402,9 @@ S_doeval(pTHX_ int gimme, CV* outside, U32 seq, HV *hh) if (CopSTASH_ne(PL_curcop, PL_curstash)) { SAVEGENERICSV(PL_curstash); - PL_curstash = (HV *)SvREFCNT_inc_simple(CopSTASH(PL_curcop)); + PL_curstash = (HV *)CopSTASH(PL_curcop); + if (SvTYPE(PL_curstash) != SVt_PVHV) PL_curstash = NULL; + else SvREFCNT_inc_simple_void(PL_curstash); } /* XXX:ajgo do we really need to alloc an AV for begin/checkunit */ SAVESPTR(PL_beginav); diff --git a/t/op/eval.t b/t/op/eval.t index 49f7494..2c61a88 100644 --- a/t/op/eval.t +++ b/t/op/eval.t @@ -6,7 +6,7 @@ BEGIN { require './test.pl'; } -plan(tests => 128); +plan(tests => 129); eval 'pass();'; @@ -618,3 +618,8 @@ syntax error at (eval 1) line 1, at EOF EOE qq'Right line number for eval "$_"'; } + +sub _117941 { package _117941; eval '$a' } +delete $::{"_117941::"}; +_117941(); +pass("eval in freed package does not crash"); -- 2.7.4