File: string-eval-leak.t

package info (click to toggle)
libautodie-perl 2.10-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 528 kB
  • ctags: 305
  • sloc: perl: 4,012; makefile: 4
file content (39 lines) | stat: -rwxr-xr-x 820 bytes parent folder | download | duplicates (13)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/perl -w
use strict;
use warnings;
use Test::More tests => 2;

# Under Perl 5.10.x, a string eval can cause a copy to be taken of
# %^H, which delays stringification of our scope guard objects,
# which in turn causes autodie to leak.  These tests check to see
# if we've successfully worked around this issue.

eval {

    {
        use autodie;
        eval "1";
    }

    open(my $fh, '<', 'this_file_had_better_not_exist');
};

TODO: {
    local $TODO;

    if ( $] >= 5.010 ) {
        $TODO = "Autodie can leak near string evals in 5.10.x";
    }

    is("$@","","Autodie should not leak out of scope");
}

# However, we can plug the leak with 'no autodie'.

no autodie;

eval {
    open(my $fh, '<', 'this_file_had_better_not_exist');
};

is("$@","",'no autodie should be able to workaround this bug');