16 my ($file, $func, $lno, $name, $size, $addr, $type);
17 if ($line =~ m/^.*(\.).*\((.*):(\d+):(.*)\(\)\) (k|v|slab-)(.*) '(.*)': (\d+) at (.*) \(tot (.*)\).*$/){
27 # we can't dump the log after portals has exited, so skip "leaks"
28 # from memory freed in the portals module unloading.
29 if ($func eq 'portals_handle_init') {
32 printf("%8s %6d bytes at %s called %s (%s:%s:%d)\n", $type, $size,
33 $addr, $name, $file, $func, $lno);
38 if (index($type, 'alloced') >= 0) {
39 if (defined($memory->{$addr})) {
40 print STDERR "*** Two allocs with the same address ($size bytes at $addr, $file:$func:$lno)\n";
41 print STDERR " first malloc at $memory->{$addr}->{file}:$memory->{$addr}->{func}:$memory->{$addr}->{lno}, second at $file:$func:$lno\n";
45 $memory->{$addr}->{name} = $name;
46 $memory->{$addr}->{size} = $size;
47 $memory->{$addr}->{file} = $file;
48 $memory->{$addr}->{func} = $func;
49 $memory->{$addr}->{lno} = $lno;
50 $memory->{$addr}->{debug_line} = $debug_line;
57 if (!defined($memory->{$addr})) {
58 print STDERR "*** Free without malloc ($size bytes at $addr, $file:$func:$lno)\n";
61 my ($oldname, $oldsize, $oldfile, $oldfunc, $oldlno) = $memory->{$addr};
63 if ($memory->{$addr}->{size} != $size) {
64 print STDERR "*** Free different size ($memory->{$addr}->{size} alloced, $size freed).\n";
65 print STDERR " malloc at $memory->{$addr}->{file}:$memory->{$addr}->{func}:$memory->{$addr}->{lno}, free at $file:$func:$lno\n";
69 delete $memory->{$addr};
72 if ($total != int($tot)) {
73 print "kernel total $tot != my total $total\n";
78 # Sort leak output by allocation time
80 return $memory->{$a}->{debug_line} <=> $memory->{$b}->{debug_line};
84 foreach $key (@sorted) {
85 my ($oldname, $oldsize, $oldfile, $oldfunc, $oldlno) = $memory->{$key};
86 print STDERR "*** Leak: $memory->{$key}->{size} bytes allocated at $key ($memory->{$key}->{file}:$memory->{$key}->{func}:$memory->{$key}->{lno}, debug file line $memory->{$key}->{debug_line})\n";
89 print STDERR "maximum used: $max, amount leaked: $total\n";