[perl #117941] eval crashes when current stash is freed
authorFather Chrysostomos <sprout@cpan.org>
Sat, 8 Jun 2013 07:11:23 +0000 (00:11 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Sat, 8 Jun 2013 07:14:12 +0000 (00:14 -0700)
pp_ctl.c
t/op/eval.t

index b3e813e..7a2ba07 100644 (file)
--- 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);
index 49f7494..2c61a88 100644 (file)
@@ -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");