Application hangs while querying Handle

delphi package - easy access to kernel objects etc.
Post Reply
Ferry van Genderen
Posts: 3
Joined: Fri Apr 07, 2006 2:31 pm
Location: The Netherlands

Application hangs while querying Handle

Post by Ferry van Genderen »

Hi,

I want to have a list of all open file handles in my process. For some reason, this causes the service to hang on a certain machine, while it works as expected on other machines. Here is the code:

Code: Select all

var
  OpenHandles: IHandles;
  CurrentHandle: IHandle;
  i: Integer;
begin
  OpenHandles := Handles({SystemWide=}False);

  for i := 0 to OpenHandles.ItemCount - 1 do
  begin
    CurrentHandle := OpenHandles.Items[i];

    if not CurrentHandle.IsStillValid then
      Continue;

    if not (CurrentHandle.ObjType in [otFile, otFileMapping]) then
      Continue;

    // other things that can be safely queried here, and that will not cause a stalled application:
    // CurrentHandle.LastErrorStr
    // CurrentHandle.KernelObj.ObjAddr
    // CurrentHandle.KernelObj.ObjTypeStr
    // CurrentHandle.KernelObj.LastErrorStr

    // Application hangs at the following call:
    if CurrentHandle.KernelObj.ObjName = '' then
      Continue;

    Report.AddRow([CurrentHandle.KernelObj.ObjName, IntToHex(CurrentHandle.Handle, 1)]);
  end;
The problem occurs on a machine with a Spanish version of Windows Server 2003. It works OK on Windows XP Professional, but I don't know whether the OS makes the difference.

The documentation does not seem to suggest other properties that can be checked prior to the ObjName to detect if that can be safely called.

Furthermore, the Handle.LastErrorStr always reads "The system cannot find the file specified", both under Spanish W2k3 and XPpro, even for handles that can be safely queries and do not cause the application to hang, and are existing files.

Help is very much appreciated!

Thank you in advance,

Ferry van Genderen
Every Angle Software Solutions B.V.
The Netherlands
madshi
Site Admin
Posts: 10754
Joined: Sun Mar 21, 2004 5:25 pm

Post by madshi »

Could you please compile the project with madExcept and then use the madTraceProcess.exe tool to analyze the freeze? That would help me quite a lot. (If you don't have a license to madExcept, you may use the non-commercial version in this specific case).

Thanks!
Post Reply