views:

712

answers:

2

A VC++ 6.0 application is crashing when doing a CString::Format operation with %d format specifier. This does not occur always but occurs when the application memory grows upto 100MB or more. ALso sometimes same crash observed when a CString copy is done. The call stack would look like this

mfc42u!CFixedAlloc::Alloc+82

mfc42u!CString::AllocBuffer+3f 00000038 00000038 005b5b64

mfc42u!CString::AllocBeforeWrite+31 00000038 0a5bfdbc 005b5b64

mfc42u!CString::AssignCopy+13 00000038 057cb83f 0a5bfe90

mfc42u!CString::operator=+4b

and this throws an access violation exception.

A: 

If you're crashing while allocating memory, then it may be due to heap corruption. Run your application under AppVerifier with the Heaps test enabled. This enable you to see various issues in your code like double frees, heap ovveruns/underruns and so on.

Michael
i understand that but my concern is it crashes in the same location repeatedly but only after the application runs upto a memory of 100MB or more. but why would heap corruption also affect string.format
Format may need to allocate memory in order to grow the internal buffer.
Michael
yeah even i thought of that but is there a case when this could happen.
A: 

This probably isn't it, but I recently came across a known issue with realloc corrupting the small block heap under VS6. If you have a realloc (or use of something like vector that uses realloc) elsewhere in your code, it could cause what you are seeing.

The fix for the issue is to either hack realloc.c, write your own realloc function, or do a "_set_sbh_threshold(0)" in your code to disable that obsolete small block heap.

T.E.D.
you should also verify you have service pack 6 installed
EvilTeach