5 # MEM mprintf.c:1094 malloc(32) = e5718
6 # MEM mprintf.c:1103 realloc(e5718, 64) = e6118
7 # MEM sendf.c:232 free(f6520)
10 if($ARGV[0] eq "-v") {
13 } while (shift @ARGV);
21 if($newtot > $maxmem) {
30 if($line =~ /^MEM ([^:]*):(\d*) (.*)/) {
31 # generic match for the filename+linenumber
36 if($function =~ /free\(0x([0-9a-f]*)/) {
38 if($sizeataddr{$addr} == 0) {
39 print "FREE ERROR: No memory allocated: $line\n";
41 elsif(-1 == $sizeataddr{$addr}) {
42 print "FREE ERROR: Memory freed twice: $line\n";
43 print "FREE ERROR: Previously freed at: ".$getmem{$addr}."\n";
47 print "malloc at ".$getmem{$addr}." is freed again at $source:$linenum\n";
50 $totalmem -= $sizeataddr{$addr};
55 $sizeataddr{$addr}=-1; # set -1 to mark as freed
56 $getmem{$addr}="$source:$linenum";
60 elsif($function =~ /malloc\((\d*)\) = 0x([0-9a-f]*)/) {
64 if($sizeataddr{$addr}>0) {
65 # this means weeeeeirdo
66 print "Fucked up debug compile, rebuild curl now\n";
69 $sizeataddr{$addr}=$size;
73 print "malloc($size) at $source:$linenum\n";
79 $getmem{$addr}="$source:$linenum";
81 elsif($function =~ /realloc\(0x([0-9a-f]*), (\d*)\) = 0x([0-9a-f]*)/) {
86 $totalmem -= $sizeataddr{$oldaddr};
87 $sizeataddr{$oldaddr}=0;
89 $totalmem += $newsize;
90 $sizeataddr{$newaddr}=$newsize;
96 $getmem{$newaddr}="$source:$linenum";
98 elsif($function =~ /strdup\(0x([0-9a-f]*)\) \((\d*)\) = 0x([0-9a-f]*)/) {
99 # strdup(a5b50) (8) = df7c0
104 $getmem{$addr}="$source:$linenum";
105 $sizeataddr{$addr}=$size;
113 print "Not recognized input line: $function\n";
116 # FD url.c:1282 socket() = 5
117 elsif($_ =~ /^FD ([^:]*):(\d*) (.*)/) {
118 # generic match for the filename+linenumber
123 if($function =~ /socket\(\) = (\d*)/) {
125 $getfile{$1}="$source:$linenum";
128 elsif($function =~ /accept\(\) = (\d*)/) {
130 $getfile{$1}="$source:$linenum";
133 elsif($function =~ /sclose\((\d*)\)/) {
134 if($filedes{$1} != 1) {
135 print "Close without open: $line\n";
138 $filedes{$1}=0; # closed now
143 # FILE url.c:1282 fopen("blabla") = 0x5ddd
144 elsif($_ =~ /^FILE ([^:]*):(\d*) (.*)/) {
145 # generic match for the filename+linenumber
150 if($function =~ /fopen\(\"([^\"]*)\"\) = (\(nil\)|0x([0-9a-f]*))/) {
156 $fopenfile{$3}="$source:$linenum";
161 elsif($function =~ /fclose\(0x([0-9a-f]*)\)/) {
163 print "fclose() without fopen(): $line\n";
172 print "Not recognized prefix line: $line\n";
177 print "Leak detected: memory still allocated: $totalmem bytes\n";
179 for(keys %sizeataddr) {
181 $size = $sizeataddr{$addr};
183 print "At $addr, there's $size bytes.\n";
184 print " allocated by ".$getmem{$addr}."\n";
191 if($filedes{$_} == 1) {
192 print "Open file descriptor created at ".$getfile{$_}."\n";
198 print "Open FILE handles left at:\n";
200 if($fopen{$_} == 1) {
201 print "fopen() called at ".$fopenfile{$_}."\n";
207 print "Mallocs: $mallocs\n",
208 "Reallocs: $reallocs\n",
209 "Strdups: $strdups\n",
212 print "Maximum allocated: $maxmem\n";