- priority: 5 --> 1
Below is a new version of the findleak.pl
script from the misc subdirectory, which
emits slightly more informative messages,
and fixes the following minor bugs:
- realloc lines were not matched, as
the number following "returns" isn't
preceded/surrounded by parentheses
- realloc matching wasn't strict about
the comma-separated second argument
- free matching wasn't strict about the
trailing/surrounding parentheses
- unmatched lines were silently ignored
instead of handed through to stdout
----------------------------------------
my %mem = {};
my %alloc = {};
while ( <> ) {
if ( /realloc\((0x[0-9a-f]+),[0-9]+\).*returns
(0x[0-9a-f]+)/ ) {
$mem{$1}--;
if ( $mem{$1} != 0 ) {
print "free before realloc: $_";
}
if ( $mem{$2} != 0 ) {
print "realloc memory leak: $_";
}
$mem{$2}++;
$alloc{$2} = $_;
} elsif ( /free\((0x[0-9a-f]+)\)/ ) {
$mem{$1}--;
if ( $mem{$1} != 0 ) {
print "free before alloc: $_";
}
} elsif ( /returns (0x[0-9a-f]+)/ ) {
if ( $mem{$1} != 0 ) {
print "alloc memory leak: $_";
}
$mem{$1}++;
$alloc{$1} = $_;
} elsif ( /null pointer is .*/ ) {
print "$_";
} else {
print "unknown line: $_";
}
}
foreach $goo ( sort keys %mem ) {
if ( $mem{$goo} ) {
print "missing free: $mem{$goo} $alloc{$goo}";
}
}