Eug*_*ota 5 delphi delphi-2009 critical-section
作为Vista认证的一部分,Microsoft希望确保应用程序退出而不保留锁定(关键部分):
测试案例31.使用指定的AppVerifier检查确认应用程序不会进入调试器(请求:3.2)
事实证明,使用Delphi 2009构建的网络应用程序确实会进入调试器,它会显示无用的消息,如下所示:
(1214.1f10): Break instruction exception - code 80000003 (first chance)
eax=00000001 ebx=07b64ff8 ecx=a6450000 edx=0007e578 esi=0017f7e0 edi=80000003
eip=77280004 esp=0017f780 ebp=0017f7ac iopl=0 nv up ei pl zr na pe nc
cs=0023 ss=002b ds=002b es=002b fs=0053 gs=002b efl=00000246
*** ERROR: Symbol file could not be found. Defaulted to export symbols for C:\Windows\SysWOW64\ntdll.dll -
ntdll!DbgBreakPoint:
77280004 cc int 3
Run Code Online (Sandbox Code Playgroud)
多次点击Go按钮后,您会遇到实际错误:
=======================================
VERIFIER STOP 00000212: pid 0x18A4: Freeing virtual memory containing an active critical section.
076CC5DC : Critical section address.
01D0191C : Critical section initialization stack trace.
075D0000 : Memory block address.
00140000 : Memory block size.
=======================================
This verifier stop is continuable.
After debugging it use `go' to continue.
=======================================
Run Code Online (Sandbox Code Playgroud)
鉴于我的代码没有泄漏TCriticalSection,我如何阻止Delphi这样做.
Eug*_*ota 13
Indy10在退出时故意泄漏关键部分.
IdStack.pas:
finalization
// Dont Free. If shutdown is from another Init section, it can cause GPF when stack
// tries to access it. App will kill it off anyways, so just let it leak
{$IFDEF IDFREEONFINAL}
FreeAndNil(GStackCriticalSection);
{$ENDIF}
Run Code Online (Sandbox Code Playgroud)
IdThread.pas:
finalization
// This call hangs if not all threads have been properly destroyed.
// But without this, bad threads can often have worse results. Catch 22.
// TIdThread.WaitAllThreadsTerminated;
{$IFDEF IDFREEONFINAL}
//only enable this if you know your code exits thread-clean
FreeAndNil(GThreadCount);
{$ENDIF}
Run Code Online (Sandbox Code Playgroud)
%delphi_home%\source\Indy\Indy10\System和%delphi_home%\source\Indy\Indy10\Core到您的项目,或将它们包括在搜索路径.IDFREEONFINAL或删除IFDEF指令.