aboutsummaryrefslogtreecommitdiffstats
path: root/misc/findleak.pl
blob: 727628b44aaf365b7bfe77680b86315c854600f2 (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
#!/usr/bin/perl
my %mem = {};
my %alloc = {};
while(<>)
{
        if (/realloc\((0x[0-9a-f]+).*\).*returns \((0x[0-9a-f]+)/)
        {
                $mem{$1}--;
                if ($mem{$1} != 0) {
                        print "free before alloc! $_";
                }
                if ($mem{$2} != 0) {
                        print "memory leak! $_";
                }
                $mem{$2}++;
                $alloc{$2} = $_;
        }
        elsif (/free\((0x[0-9a-f]+)/)
        {
                $mem{$1}--;
                if ($mem{$1} != 0) {
                        print "free before alloc! $_";
                }
        }
        elsif (m/returns (0x[0-9a-f]+)/)
        {
                if ($mem{$1} != 0) {
                        print "memory leak! $_";
                }
                $mem{$1}++;
                $alloc{$1} = $_;
        }
}
foreach $goo (sort keys %mem)
{
        if ($mem{$goo})
        {
                print "$mem{$goo} $alloc{$goo}";
        }
}
# From: Ed Beroset <beroset@mindspring.com>