overlappedFreeError MDA

注释

本文特定于 .NET Framework。 它不适用于 .NET 的较新版本实现,包括 .NET 6 及更高版本。

overlappedFreeError 在重叠操作完成之前调用方法时 Overlapped.Free(NativeOverlapped*) ,将激活托管调试助手(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.

配置

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

另见