Home > Software engineering >  Completion port receiving udp in release mode memory access conflict
Completion port receiving udp in release mode memory access conflict

Time:11-21

When using the completion port receive udp data, the debug mode is normal, but in release mode memory access conflict error, data length is not more than the cache size
Receive function is as follows:

//handle receiving udp data
Void tagPER_SOCK_CONTEXT: : DoRecvUdp (PER_IO_CONTEXT * pIoContext,
DWORD dwLen, int iThreadId) {
Try {
The EnterCriticalSection (& amp; RcvUdpDataIocpSection);
IRcvNum++;
If (this - & gt; RcvDataHandler)
(* (this - & gt; RcvDataHandler)) (this - & gt; ClientData,
(unsigned char *) pIoContext - & gt; M_szBuffer dwLen, pIoContext - & gt; Addr, 0);

Bool BRST=this - & gt; PostRecvUdp (pIoContext iThreadId);

LeaveCriticalSection (& amp; RcvUdpDataIocpSection);

}
The catch (... ) {
//STD: : cout & lt; <"Catch erro.";
}
}

CodePudding user response:

Your code problem, this problem I met,
The Debug memory is initialized, the Release no.

CodePudding user response:

Dot Release under the log out, first locate the problem of function, check the pointer is valid, the reference is the memory of the early Release, etc. ~

CodePudding user response:

reference 1/f, walk every step response:
you code problem, this problem I met,
The Debug memory is initialized, the Release no.

What memory initialization, application of new spatial data reset?

CodePudding user response:

refer to the second floor 7-eleven's response:
Release dot under the log out, first locate the problem of function, check the pointer is valid, the reference is the memory of the early Release, etc. ~

In iRcvNum++; Under the line to see the data at that time also didn't found the problem, at least is effective, and the function is the direct reference in the iocp thread function
 
BOOL bReturn=GetQueuedCompletionStatus (svrInfo - & gt; M_hIOCompletionPort, & amp; DwBytesTransferred, (PULONG_PTR) & amp; PSocketContext, & amp; POverLapped, INFINITE);

if (! BReturn) {
DWORD dErr=GetLastError ();
PER_IO_CONTEXT * pIoContext=CONTAINING_RECORD (pOverLapped PER_IO_CONTEXT, overLapped);
SvrInfo - & gt; HandleQueueCompletionErr (pSocketContext pIoContext, dErr);
}
The else {
PER_IO_CONTEXT * pIoContext=CONTAINING_RECORD (pOverLapped PER_IO_CONTEXT, overLapped);
The switch (pIoContext - & gt; OpType)
{
Case RECVUDP_POST:
If (pSocketContext) {
PSocketContext - & gt; DoRecvUdp (pIoContext dwBytesTransferred, iThreadId);
}
}
}

CodePudding user response:

reference ima_zhan reply: 3/f
Quote: refer to 1st floor walk every step response:

Your code problem, this problem I met,
The Debug memory is initialized, the Release no.

What memory initialization, application of new spatial data reset?



Is the new memory blocks under the debug and the release of the new memory CARDS, there is a difference between

CodePudding user response:

And release behavior is different also,

Some released is still there, still can use, is random behavior,
Some released it didn't, not can use, access to collapse,

Carefully check code, it is related to your personal habit of writing code,
1, after the new memory, whether memset
2, after the delete memory, is given a NULL pointer, the existence of wild pointer
3, before using a pointer, whether the judgement is not empty reuse,
4, whether the compiler warnings for the highest level
5, strcpy is abandoned, use strncpy, these VS a large number of abandoned function, whether to switch to the new security function

CodePudding user response:

refer to the original poster ima_zhan response:
when using the completion port receive udp data, the debug mode is normal, but in release mode memory access conflict error, data length is not more than the cache size
Receive function is as follows:

//handle receiving udp data
Void tagPER_SOCK_CONTEXT: : DoRecvUdp (PER_IO_CONTEXT * pIoContext,
DWORD dwLen, int iThreadId) {
Try {
The EnterCriticalSection (& amp; RcvUdpDataIocpSection);
IRcvNum++;
If (this - & gt; RcvDataHandler)
(* (this - & gt; RcvDataHandler)) (this - & gt; ClientData,
(unsigned char *) pIoContext - & gt; M_szBuffer dwLen, pIoContext - & gt; Addr, 0);

Bool BRST=this - & gt; PostRecvUdp (pIoContext iThreadId);

LeaveCriticalSection (& amp; RcvUdpDataIocpSection);

}
The catch (... ) {
//STD: : cout & lt; <"Catch erro.";
}
}



This code is a fatal problem,
Among EnterCriticalSection or LeaveCriticalSection when used in pairs, there can be no return, there can be no exception!!!!!!!!!!!!!!!
Otherwise would be a deadlock!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
You can either write a CLock or using boost, or in the c + + 11 lockguard

Try
{
CLock lock;//object automatically locks, lock when created, when the object is destroyed automatically unlock
}
The catch (... )
{
}

CodePudding user response:

Condition fully, use __try __except capture SEH exception

 

The EnterCriticalSection (& amp; RcvUdpDataIocpSection);

IRcvNum++;
__try
{
If (rcvDataHandler
& & PIoContext
& & PIoContext - & gt; M_szBuffer
& &//conditions to determine full
& & 1)
{
(* (this - & gt; RcvDataHandler)) (this - & gt; ClientData,
(unsigned char *) pIoContext - & gt; M_szBuffer dwLen, pIoContext - & gt; Addr, 0);
}
Bool BRST=this - & gt; PostRecvUdp (pIoContext iThreadId);
}
__except (GetExceptionCode ()==EXCEPTION_ACCESS_VIOLATION)
{
ASSERT (FALSE);
}

LeaveCriticalSection (& amp; RcvUdpDataIocpSection);



CodePudding user response:

reference 4 floor ima_zhan response:
Quote: refer to the second floor 7-eleven's response:

Dot Release under the log out, first locate the problem of function, check the pointer is valid, the reference is the memory of the early Release, etc. ~

In iRcvNum++; Under the line to see the data at that time also didn't found the problem, at least is effective, and the function is the direct reference in the iocp thread function
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related