overlappedFreeError MDA

如果在重叠操作完成之前调用 Overlapped.Free(NativeOverlapped*) 方法,将激活 overlappedFreeError 托管调试助手 (MDA)。

症状

访问冲突或垃圾回收堆损坏。

原因

操作完成之前,已释放重叠结构。 使用重叠指针的函数可能稍后会在释放结构后写入结构。 由于另一个对象当前可能占用该区域,这可能会导致堆损坏。

如果重叠操作未成功开始,则此 MDA 可能不表示错误。

解决方法

在调用 Free(NativeOverlapped*) 方法之前,确保已完成使用重叠结构的 I/O 操作。

对运行时的影响

此 MDA 对 CLR 无任何影响。

输出

以下是此 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>  

请参阅