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