views:

171

answers:

3

Hi

I am observing a crash within my application and the call stack shows below

mfc42u!CString::AllocBeforeWrite+5    
mfc42u!CString::operator=+22

No idea why this occuring. This does not occur frequently also. Any suggestions would help. I have the crash dump with me but not able to progress any further.

The operation i am performing is something like this

iParseErr += m_RawMessage[wMsgLen-32] != NC_SP;

where m_RawMessage is a 512 length char array. wMsgLen is unsigned short and NC_SP is defined as

#define NC_SP   0x20     // Space

EDIT:

Call Stack:

042afe3c 5f8090dd mfc42u!CString::AllocBeforeWrite+0x5 * WARNING: Unable to verify checksum for WP Communications Server.exe 
042afe50 0045f0c0 mfc42u!CString::operator=+0x22 
042aff10 5f814d6b WP_Communications_Server!CParserN1000::iCheckMessage(void)+0x665 [V:\CSAC\SourceCode\WP Communications Server\HW Parser N1000.cpp @ 1279] 
042aff80 77c3a3b0 mfc42u!_AfxThreadEntry+0xe6 
042affb4 7c80b729 msvcrt!_endthreadex+0xa9
042affec 00000000 kernel32!BaseThreadStart+0x37

Well this is complete call stack and i have posted the code snipped as in my original message

Thanks

A: 
  1. Can you post complete call stack?
  2. Code snippet where exactly crash is occured?

Chandu

042afe3c 5f8090dd mfc42u!CString::AllocBeforeWrite+0x5*** WARNING: Unable to verify checksum for WP Communications Server.exe042afe50 0045f0c0 mfc42u!CString::operator=+0x22042aff10 5f814d6b WP_Communications_Server!CParserN1000::iCheckMessage(void)+0x665 [V:\CSAC\SourceCode\WP Communications Server\HW Parser N1000.cpp @ 1279]042aff80 77c3a3b0 mfc42u!_AfxThreadEntry+0xe6042affb4 7c80b729 msvcrt!_endthreadex+0xa9042affec 00000000 kernel32!BaseThreadStart+0x37Well this is complete call stack and i have posted the code snipped as in my original message
ckv
A: 

I'm sure you'll have checked the obvious: wMsgLen >= 32

harriyott
yes that is taken care of
ckv
+4  A: 

I have a suggestion that might be a little frustrating for you:

CString::AllocBeforeWrite does implicate to me, that the system tries to allocate some memory.

Could it be, that some other memory operation (specially freeing or resizing of memory) is corrupted before?

A typical problem with C/C++ memory management is, that an error on freeing (or resizing) memory (for example two times freeing the same junk of memory) will not crash the system immediatly but can cause dumps much later -- specially when new memory is to be allocated.

Your situation looks to me quite like that.

The bad thing is:

It can be very difficult to find the place where the real error occurs -- where the heap is corrupted in the first place.

This also can be the reason, why your problem only occurs once in a while. It could depend on some complicated situation beforehand.

Juergen
What you have said is quite possible. so it makes my job all the more tough hmm . ok Thanks
ckv