Posted on 2009-04-02 19:10
S.l.e!ep.¢% 阅读(2103)
评论(4) 编辑 收藏 引用 所属分类:
WinDbg
内存崩溃的BUG
内存崩溃的BUG (2)
内存崩溃的BUG (3)
连续三天在跟踪同个问题!!!!!!!!
今天重现了几次问题,都是下面的原因导致的。
首先要说下IOCP的实现
下面的发送包时的代码
-------------------------------------------------------------------------
PER_IO_CONTEXT* overlappedEx=new PER_IO_CONTEXT
overlappedEx->IOOperation= WRITE;
overlappedEx->wsabuf.buf= (char *)malloc( nLen );
if( NULL == overlappedEx->wsabuf.buf )
{
delete overlappedEx;
return -1;
}
if(WSASend(m_socket,&(overlappedEx->wsabuf), 0x01, &dwBytes, 0x00, &(overlappedEx->Overlapped), NULL ) == SOCKET_ERROR)
-------------------------------------------------------------------------
下面是完成端口通知时的处理代码
-------------------------------------------------------------------------
while (m_bIsRun)
{
result = GetQueuedCompletionStatus(m_hCompletionPort,&iosize,&key,&overlapped,INFINITE);
if ( 0 == key )
{
break;
}
if( NULL != overlappedEx )
{
if ( WRITE == overlappedEx->IOOperation )
{
delete overlappedEx;
continue;
}
}
……
}
-------------------------------------------------------------------------
之后在 delete overlappedEx; 前面用 OutPutDebugString 打印了调试信息, 发现在
delete overlappedEx; 执行后
WSASend 里面还会访问到 overlappedEx 下面的 Overlapped,结果就在 WSASend 出错了
overlappedEx 的结构体定义如下:
struct PER_IO_CONTEXT
{
WSAOVERLAPPED Overlapped;
WSABUF wsabuf;
IO_OPERATION IOOperation;
};
查了下 MSDN WSASend 函数的说明,无头绪,明天继续