3 # This Source Code Form is subject to the terms of the Mozilla Public
4 # License, v. 2.0. If a copy of the MPL was not distributed with this
5 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 # Script loosely based on Chris Waterson's find-leakers.pl and make-tree.pl
13 # GetOption will create $opt_object, so ignore the
14 # warning that gets spit out about those vbls.
15 GetOptions
("object=s", "list", "help");
17 # use $::opt_help twice to eliminate warning...
18 ($::opt_help
) && ($::opt_help
) && die qq{
19 usage
: find
-comptr
-leakers
.pl
< logfile
20 --object
<obj
> Examine only object
<obj
>
21 --list Only list leaked objects
22 --help This message
:-)
26 warn "Examining only object $::opt_object (THIS IS BROKEN)\n";
28 warn "Examining all objects\n";
47 if ($op eq 'nsCOMPtrAddRef') {
48 push @
{ $allocs{$sno}->{$ptr} }, [ +1, $strace ];
50 elsif ($op eq 'nsCOMPtrRelease') {
51 push @
{ $allocs{$sno}->{$ptr} }, [ -1, $strace ];
53 my @ptrallocs = @
{ $allocs{$sno}->{$ptr} };
54 foreach my $alloc (@ptrallocs) {
58 delete($allocs{$sno}{$ptr});
65 chop; # avoid \n in $ptr
66 my @fields = split(/ /, $_);
68 ($class, $obj, $sno, $op, $cnt, $ptr) = @fields;
74 } elsif (!($::opt_object
) || ($::opt_object
eq $obj)) {
77 } elsif ( $accumulating == 1 ) {
83 $strace = $strace . $_;
87 if ( $accumulating == 1) {
91 foreach my $serial (keys(%allocs)) {
92 foreach my $comptr (keys( %{$allocs{$serial}} )) {
94 my @ptrallocs = @
{ $allocs{$serial}->{$comptr} };
95 foreach my $alloc (@ptrallocs) {
98 print "Object ", $serial, " held by ", $comptr, " is ", $sum, " out of balance.\n";
99 unless ($::opt_list
) {
101 foreach my $alloc (@ptrallocs) {
102 if (@
$alloc[0] == +1) {
103 print "Put into nsCOMPtr at:\n";
104 } elsif (@
$alloc[0] == -1) {
105 print "Released from nsCOMPtr at:\n";
107 print @
$alloc[1]; # the stack trace