summaryrefslogtreecommitdiff
path: root/scripts/test_leaks.pl
blob: 1fbc7b9efc3bc79f9412d2758dc1fec7dfeee0bb (plain)
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
#!/usr/bin/perl

# Copyright (c) 2003 America Online, Inc.  All rights reserved.

# A crude, simple script that looks at "loss record" (stacks) in valgrind 
# output, and if the stack contains any of the funcs to ignore, then it 
# skips that stack else the stack is printed.

# syntax 
#   test_leaks.pl <file containing funcs to ignore> <valgrind output file>


$ignore_file = shift @ARGV;
$valgrind_output = shift @ARGV;

# gather funcs to ignore
open(IN, "$ignore_file") || die "Unable to open file $ignore_file";
$i=0;
while(<IN>) {
    chop;
    $ignore[$i++] = $_;
}
close IN;

# now walk through the valgrind output
open(IN, "$valgrind_output") || die "Unable to open file $valgrind_output";
while(<IN>) {
    if (/==\d+==.*loss record.*\n/) {
	$line=$_;
	next;
    } else {
	if (/==\d+== \n/ && $line) {
            $i=0;
            $bad=0;
            while ($ignore[$i]) {
	        if ($line =~ /$ignore[$i]/) {
                    #printf "STACK TO BE IGNORED : \n%s\n", $line;
		    $bad=1;
		    break;
                }
		$i++;
	    }

	    # if none of the patterns matched...
	    if ($bad==0) {
                printf "STACK TO EXAMINE: \n%s\n", $line;
	    }

	    undef $line;
	    next;
	}

	if ($line) {
	    $line=$line.$_;
	}
   
   }
}
close IN;