File: memleak.ot

package info (click to toggle)
libaudio-scan-perl 0.93%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 6,152 kB
  • ctags: 1,728
  • sloc: ansic: 11,482; perl: 241; sh: 51; makefile: 2
file content (94 lines) | stat: -rw-r--r-- 2,333 bytes parent folder | download | duplicates (5)
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# Check for memory leaks in all test files, in both scan and seek modes

use strict;

use FindBin;
use lib "$FindBin::Bin/lib";
use Test::More;
use File::Next;
use Audio::Scan;
eval "use Proc::ProcessTable";

plan skip_all => 'Proc::ProcessTable required for this test' if $@;

plan tests => 464;

$ENV{AUDIO_SCAN_NO_ARTWORK} = 1;

my $custom_dir = shift;

our $t = Proc::ProcessTable->new( cache_ttys => 1 );
our ( $initial, $final ) = ( 0, 0 );

my $files = File::Next::files(
    { file_filter => sub { Audio::Scan->is_supported($_) } },
    $custom_dir || $FindBin::Bin,
);

while ( defined ( my $file = $files->() ) ) {
    print "# $file\n";
    
    # Test scan leak
    {
        for ( 1 .. 3 ) {
            my $s = Audio::Scan->scan($file);
        }
        $initial = size_of();
        for ( 1 .. 2000 ) {
            my $s = Audio::Scan->scan($file);
        }
        $final = size_of();
        is( $final - $initial, 0, "$file scan not leaking" );
    }
    
    # Test artwork mode leak
    {
        local $ENV{AUDIO_SCAN_NO_ARTWORK} = 0;
        
        for ( 1 .. 3 ) {
            my $s = Audio::Scan->scan($file);
        }
        $initial = size_of();
        for ( 1 .. 2000 ) {
            my $s = Audio::Scan->scan($file);
        }
        $final = size_of();
        is( $final - $initial, 0, "$file artwork mode scan not leaking" );
    }        
    
    # Test seek leak
    {
        if ( $file =~ /\.m4a$/ ) {
            for ( 1 .. 3 ) {
                Audio::Scan->find_frame_return_info( $file, 10 );
            }
            $initial = size_of();
            for ( 1 .. 2000 ) {
                Audio::Scan->find_frame_return_info( $file, 10 );
            }
            $final = size_of();
            is( $final - $initial, 0, "$file seek not leaking" );
        }
        else {
            for ( 1 .. 3 ) {
                Audio::Scan->find_frame( $file, 10 );
            }
            $initial = size_of();
            for ( 1 .. 2000 ) {
                Audio::Scan->find_frame( $file, 10 );
            }
            $final = size_of();
            is( $final - $initial, 0, "$file seek not leaking" );
        }
    }
}

sub size_of {
    foreach my $p ( @{ $t->table } ) {
        if ( $p->pid == $$ ) {
            return $p->rss;
        }
    }
    
    die "PID not found?";
}