#! /usr/bin/perl -w

# Find unmatched calls to GDI_AllocObject/GDI_FreeObject

use strict;
use bytes;

my @allocs;
my @nos;
my $line_no = 1;

while(<>)
{
  my $line = $_;

  $line =~ s/\n//g;

  if ( $line =~ /GDI allocate/ )
  {
    my $addr;

    $line =~ s/.*?returning 0x(.*)?$/$1/g;

    push (@allocs, $line);
    push (@nos, $line_no);
  }

  if ( $line =~ /GDI free/ )
  {
    my $addr;
    my $num = 0;
    my $found = 0;
    $line =~ s/.*?0x.*?0x(.*)?$/$1/g;

    while(defined($allocs[$num]) && $found < 1)
    {
      if ($allocs[$num] eq $line)
      {
        $found = 1;
	$allocs[$num] = " ";
      }
     $num = $num+1;
    }
  }
  $line_no += 1;
}

my $i = 0;

    while(defined($allocs[$i]))
    {
    if ($allocs[$i] ne " ")
    {
    print "\'".$allocs[$i]."\' ".$nos[$i]."\n";
    }
    $i = $i+1;
    }
