diff options
-rwxr-xr-x | memanalyze.pl | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/memanalyze.pl b/memanalyze.pl index aa6db4c81..86c967c8c 100755 --- a/memanalyze.pl +++ b/memanalyze.pl @@ -26,13 +26,17 @@ while(<STDIN>) { if($function =~ /free\(0x([0-9a-f]*)/) { $addr = $1; - if($sizeataddr{$addr} <= 0) { + if($sizeataddr{$addr} == 0) { print "FREE ERROR: No memory allocated: $line\n"; } + elsif(-1 == $sizeataddr{$addr}) { + print "FREE ERROR: Memory freed twice: $line\n"; + print "FREE ERROR: Previously freed at: ".$getmem{$addr}."\n"; + } else { $totalmem -= $sizeataddr{$addr}; - $sizeataddr{$addr}=0; - $getmem{$addr}=""; # forget after a good free() + $sizeataddr{$addr}=-1; # set -1 to mark as freed + $getmem{$addr}="$source:$linenum"; } } elsif($function =~ /malloc\((\d*)\) = 0x([0-9a-f]*)/) { |