overlappedFreeError MDA

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

症状

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

原因

重叠结构在操作完成之前释放。 正在使用重叠指针的函数随后可能在已释放该结构之后写入该结构。 那样会导致堆损坏,因为另一个对象现在可能正占用该区域。

如果重叠操作未成功启动,此 MDA 可能并不表示错误。

解决方法

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

对运行时的影响

此 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.

配置

<mdaConfig>
  <assistants>
    <overlappedFreeError/>
  </assistants>
</mdaConfig>

请参见

参考

MarshalAsAttribute

概念

使用托管调试助手诊断错误

互操作封送处理