use crosssocket, av and error leak reported

delphi package - automated exception handling

use crosssocket, av and error leak reported

Postby advwang » Fri Mar 15, 2019 4:52 am

use crosssocket, when application exit,

1.an AV error ocurred with stack:

:7748058c ntdll.ZwQueryObject + 0xc
:671a1c7c ; C:\Dev32\madCollection\madExcept\Dlls\madExcept32.dll
:671b4c07 ; C:\Dev32\madCollection\madExcept\Dlls\madExcept32.dll
:671b93c0 ; C:\Dev32\madCollection\madExcept\Dlls\madExcept32.dll
:671a4eaa madExcept32.SetLeakOption + 0xd6
System._Halt0
:0040a5b6 @Halt0 + $116
:77320179 KERNEL32.BaseThreadInitThunk + 0x19
:7747662d ntdll.RtlGetAppContainerNamedObjectPath + 0xed
:774765fd ntdll.RtlGetAppContainerNamedObjectPath + 0xbd

2.an leak reported, but the handle freed already.

allocation number: 2629
program up time: 1.12 s
type: IoCompletion Handle
handle: $a88

main thread ($c64):
671aadfa madExcept32.dll madExceptDbg 4397 CreateIoCompletionPortCallback
0069bd01 Project1.exe Net.CrossSocket.Iocp 333 TIocpCrossSocket.StartLoop
00686470 Project1.exe Net.CrossSocket.Base 1002 TAbstractCrossSocket.AfterConstruction
00408f75 Project1.exe System 18822 @AfterConstruction
006f48a4 Project1.exe Net.CrossHttpServer 2524 TCrossHttpServer.Create
00700948 Project1.exe sdLinuxHttpServer 36 TsdLinuxHttpServer.Create
0070154c Project1.exe Unit1 131 TForm1.Button1Click
005bbed7 Project1.exe Vcl.Controls 7536 TControl.Click
005d37b6 Project1.exe Vcl.StdCtrls 5462 TCustomButton.Click
005d42cc Project1.exe Vcl.StdCtrls 5923 TCustomButton.CNCommand
005bb97e Project1.exe Vcl.Controls 7420 TControl.WndProc
005c0433 Project1.exe Vcl.Controls 10278 TWinControl.WndProc
005d3460 Project1.exe Vcl.StdCtrls 5299 TButtonControl.WndProc
005bb5b8 Project1.exe Vcl.Controls 7198 TControl.Perform
005c0597 Project1.exe Vcl.Controls 10347 DoControlMsg
005c101b Project1.exe Vcl.Controls 10622 TWinControl.WMCommand
00664ccd Project1.exe Vcl.Forms 6465 TCustomForm.WMCommand
005bb97e Project1.exe Vcl.Controls 7420 TControl.WndProc
005c0433 Project1.exe Vcl.Controls 10278 TWinControl.WndProc
0040930c Project1.exe System 19114 TMonitor.Enter
00409178 Project1.exe System 19028 TMonitor.CheckOwningThread
0040949a Project1.exe System 19218 TMonitor.Exit
004094f6 Project1.exe System 19240 TMonitor.Exit
00597e17 Project1.exe Vcl.Graphics 7130 FreeMemoryContexts
0066194d Project1.exe Vcl.Forms 4629 TCustomForm.WndProc
005bfa00 Project1.exe Vcl.Controls 9977 TWinControl.MainWndProc
004ed6e4 Project1.exe System.Classes 17536 StdWndProc
751f670e USER32.dll SendMessageW
751f67ea USER32.dll CallWindowProcW
005c0542 Project1.exe Vcl.Controls 10319 TWinControl.DefaultHandler
005c0433 Project1.exe Vcl.Controls 10278 TWinControl.WndProc
005d3460 Project1.exe Vcl.StdCtrls 5299 TButtonControl.WndProc
004ed6e4 Project1.exe System.Classes 17536 StdWndProc
751f61ab USER32.dll DispatchMessageW
0066b33b Project1.exe Vcl.Forms 10724 TApplication.ProcessMessage



procedure TIocpCrossSocket.StartLoop;
var
I: Integer;
LCrossSocket: ICrossSocket;
begin
if (FIoThreads <> nil) then Exit;

FIocpHandle := CreateIoCompletionPort(INVALID_HANDLE_VALUE, 0, 0, 0); <------------------------Create
LCrossSocket := Self;
SetLength(FIoThreads, GetIoThreads);
for I := 0 to Length(FIoThreads) - 1 do
FIoThreads[I] := TIoEventThread.Create(LCrossSocket);
end;


procedure TIocpCrossSocket.StopLoop;
var
I: Integer;
LCurrentThreadID: TThreadID;
begin
if (FIoThreads = nil) then Exit;

CloseAll;

while (ListensCount > 0) or (ConnectionsCount > 0) do Sleep(1);

for I := 0 to Length(FIoThreads) - 1 do
PostQueuedCompletionStatus(FIocpHandle, 0, 0, POverlapped(SHUTDOWN_FLAG));

LCurrentThreadID := GetCurrentThreadId;
for I := 0 to Length(FIoThreads) - 1 do
begin
if (FIoThreads[I].ThreadID = LCurrentThreadID) then
raise ECrossSocket.Create('不能在IO线程中执行StopLoop!');

FIoThreads[I].WaitFor;
FreeAndNil(FIoThreads[I]);
end;
FIoThreads := nil;

if not CloseHandle(FIocpHandle) then <---------------------------------------------Free
RaiseLastOSError;
end;
Attachments
Crosss_Mad_Issue.part2.rar
(57.66 KiB) Downloaded 4 times
Crosss_Mad_Issue.part1.rar
(200 KiB) Downloaded 4 times
advwang
 
Posts: 1
Joined: Fri Mar 15, 2019 4:48 am

Re: use crosssocket, av and error leak reported

Postby madshi » Mon Mar 18, 2019 11:13 am

Found the problem: In unit "Net.CrossSocket.Iocp.pas" line 567 the API "CreateIoCompletionPort" is called again, with the same "FIocpHandle" handle. Called like this, CreateIoCompletionPort actually doesn't create a new completion port, but just returns the old one. The madExcept leak logic didn't understand that and thought a new port was being created. So actually madExcept had two leaks recorded for the same port. Calling CloseHandle() only closed one of them.

This will be fixed in the next build, thanks for your report. The test project was *great*, btw. Very nicely done, compiled well and breakpoints already set. Thanks for that!
madshi
Site Admin
 
Posts: 9960
Joined: Sun Mar 21, 2004 5:25 pm


Return to madExcept

Who is online

Users browsing this forum: No registered users and 4 guests