xref: /openbsd-src/gnu/usr.bin/perl/cpan/autodie/t/string-eval-leak.t (revision b39c515898423c8d899e35282f4b395f7cad3298)
1*b39c5158Smillert#!/usr/bin/perl -w
2*b39c5158Smillertuse strict;
3*b39c5158Smillertuse warnings;
4*b39c5158Smillertuse Test::More tests => 2;
5*b39c5158Smillert
6*b39c5158Smillert# Under Perl 5.10.x, a string eval can cause a copy to be taken of
7*b39c5158Smillert# %^H, which delays stringification of our scope guard objects,
8*b39c5158Smillert# which in turn causes autodie to leak.  These tests check to see
9*b39c5158Smillert# if we've successfully worked around this issue.
10*b39c5158Smillert
11*b39c5158Smillerteval {
12*b39c5158Smillert
13*b39c5158Smillert    {
14*b39c5158Smillert        use autodie;
15*b39c5158Smillert        eval "1";
16*b39c5158Smillert    }
17*b39c5158Smillert
18*b39c5158Smillert    open(my $fh, '<', 'this_file_had_better_not_exist');
19*b39c5158Smillert};
20*b39c5158Smillert
21*b39c5158SmillertTODO: {
22*b39c5158Smillert    local $TODO;
23*b39c5158Smillert
24*b39c5158Smillert    if ( $] >= 5.010 ) {
25*b39c5158Smillert        $TODO = "Autodie can leak near string evals in 5.10.x";
26*b39c5158Smillert    }
27*b39c5158Smillert
28*b39c5158Smillert    is("$@","","Autodie should not leak out of scope");
29*b39c5158Smillert}
30*b39c5158Smillert
31*b39c5158Smillert# However, we can plug the leak with 'no autodie'.
32*b39c5158Smillert
33*b39c5158Smillertno autodie;
34*b39c5158Smillert
35*b39c5158Smillerteval {
36*b39c5158Smillert    open(my $fh, '<', 'this_file_had_better_not_exist');
37*b39c5158Smillert};
38*b39c5158Smillert
39*b39c5158Smillertis("$@","",'no autodie should be able to workaround this bug');
40