16 my ($file, $func, $lno, $name, $size, $addr, $type);
17 if ($line =~ m/^.*(\.).*\((.*):(\d+):(.*)\(\)\) (k|v|slab-)(.*) '(.*)': (\d+) at ([\da-f]+)/){
26 # we can't dump the log after portals has exited, so skip "leaks"
27 # from memory freed in the portals module unloading.
28 if ($func eq 'portals_handle_init') {
31 printf("%8s %6d bytes at %s called %s (%s:%s:%d)\n", $type, $size,
32 $addr, $name, $file, $func, $lno);
37 if (index($type, 'alloced') >= 0) {
38 if (defined($memory->{$addr})) {
39 print STDERR "*** Two allocs with the same address ($size bytes at $addr, $file:$func:$lno)\n";
40 print STDERR " first malloc at $memory->{$addr}->{file}:$memory->{$addr}->{func}:$memory->{$addr}->{lno}, second at $file:$func:$lno\n";
44 $memory->{$addr}->{name} = $name;
45 $memory->{$addr}->{size} = $size;
46 $memory->{$addr}->{file} = $file;
47 $memory->{$addr}->{func} = $func;
48 $memory->{$addr}->{lno} = $lno;
49 $memory->{$addr}->{debug_line} = $debug_line;
56 if (!defined($memory->{$addr})) {
57 print STDERR "*** Free without malloc ($size bytes at $addr, $file:$func:$lno)\n";
60 my ($oldname, $oldsize, $oldfile, $oldfunc, $oldlno) = $memory->{$addr};
62 if ($memory->{$addr}->{size} != $size) {
63 print STDERR "*** Free different size ($memory->{$addr}->{size} alloced, $size freed).\n";
64 print STDERR " malloc at $memory->{$addr}->{file}:$memory->{$addr}->{func}:$memory->{$addr}->{lno}, free at $file:$func:$lno\n";
68 delete $memory->{$addr};
73 # Sort leak output by allocation time
75 return $memory->{$a}->{debug_line} <=> $memory->{$b}->{debug_line};
79 foreach $key (@sorted) {
80 my ($oldname, $oldsize, $oldfile, $oldfunc, $oldlno) = $memory->{$key};
81 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";
84 print STDERR "maximum used: $max, amount leaked: $total\n";