}
} while (shift @ARGV);
+my $maxmem;
+
+sub newtotal {
+ my ($newtot)=@_;
+ # count a max here
+
+ if($newtot > $maxmem) {
+ $maxmem= $newtot;
+ }
+}
+
while(<STDIN>) {
chomp $_;
$line = $_;
- if($verbose) {
- print "IN: $line\n";
- }
+
if($line =~ /^MEM ([^:]*):(\d*) (.*)/) {
# generic match for the filename+linenumber
$source = $1;
print "FREE ERROR: Previously freed at: ".$getmem{$addr}."\n";
}
else {
+ if(0 && $verbose) {
+ print "malloc at ".$getmem{$addr}." is freed again at $source:$linenum\n";
+ }
+
$totalmem -= $sizeataddr{$addr};
+
+ newtotal($totalmem);
+ $frees++;
+
$sizeataddr{$addr}=-1; # set -1 to mark as freed
$getmem{$addr}="$source:$linenum";
+
}
}
elsif($function =~ /malloc\((\d*)\) = 0x([0-9a-f]*)/) {
$size = $1;
$addr = $2;
+
+ if($sizeataddr{$addr}>0) {
+ # this means weeeeeirdo
+ print "Fucked up debug compile, rebuild curl now\n";
+ }
+
$sizeataddr{$addr}=$size;
$totalmem += $size;
+ if(0 && $verbose) {
+ print "malloc($size) at $source:$linenum\n";
+ }
+
+ newtotal($totalmem);
+ $mallocs++;
+
$getmem{$addr}="$source:$linenum";
}
elsif($function =~ /realloc\(0x([0-9a-f]*), (\d*)\) = 0x([0-9a-f]*)/) {
$totalmem += $newsize;
$sizeataddr{$newaddr}=$newsize;
+ newtotal($totalmem);
+ $reallocs++;
+
$getmem{$oldaddr}="";
$getmem{$newaddr}="$source:$linenum";
}
$sizeataddr{$addr}=$size;
$totalmem += $size;
+
+ newtotal($totalmem);
+ $strdups++;
}
else {
print "Not recognized input line: $function\n";
else {
print "Not recognized prefix line: $line\n";
}
- if($verbose) {
- print "TOTAL: $totalmem\n";
- }
}
if($totalmem) {
}
}
}
+
+if($verbose) {
+ print "Mallocs: $mallocs\n",
+ "Reallocs: $reallocs\n",
+ "Strdups: $strdups\n",
+ "Frees: $frees\n";
+
+ print "Maximum allocated: $maxmem\n";
+}