summaryrefslogtreecommitdiff
path: root/misc/findleak.txt
blob: 8a1cfdc168e3266d9d228553755c642044078cb4 (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
Subject: [nasm-devel] tool to help find memory leaks
Date: Fri, 02 Nov 2001 22:08:01 -0500
From: Ed Beroset <beroset@mindspring.com>
Reply-To: nasm-devel@yahoogroups.com
To: nasm-devel@yahoogroups.com

Here's a little Perl script I wrote a while ago to help track down memory
leaks in nasm.  First, compile nasm with LOGALLOC defined (see
nasmlib.c).  That creates a log file of all allocs and frees.  This Perl
script reads that file and tells you which source code lines caused a leak
(or a free of unallocated memory).  There are many leaks, almost all of
them in the preprocessor.

-+--- findleak.pl begins
#!/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}";
        }
}
-+--- findleak.pl ends



Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/