Note
本文專指 .NET 框架。 此規定不適用於較新的 .NET 實作,包括 .NET 6 及更新版本。
overlappedFreeError當Overlapped.Free(NativeOverlapped*)方法在重疊操作尚未完成前被呼叫時,管理除錯助理(MDA)就會被啟動。
Symptoms
垃圾回收堆積的存取違規或損壞。
原因
在作業完成前,一個重疊的結構被解開。 使用重疊指標的函式可能會在結構被釋放後再寫入。 這可能導致堆積損壞,因為另一個物件可能佔據該區域。
如果重疊操作未成功啟動,此 MDA 可能不代表錯誤。
解決方法
在呼叫該 Free(NativeOverlapped*) 方法前,請確保使用重疊結構的 I/O 操作已完成。
對運行時間的影響
此 MDA 對 CLR 沒有影響。
Output
以下是此 MDA 的樣本輸出。
An overlapped pointer (0x00ea3430) that was not allocated on the GC heap was passed via Pinvoke to the win32 function 'WriteFile' in module 'KERNEL32.DLL'. If the AppDomain is shut down, this can cause heap corruption when the async I/O completes. The best solution is to pass a NativeOverlappedStructure retrieved from a call to System.Threading.Overlapped.Pack(). If the AppDomain exits, the CLR will keep this structure alive and pinned until the I/O completes.
Configuration
<mdaConfig>
<assistants>
<overlappedFreeError/>
</assistants>
</mdaConfig>