crash problem with release build (vc7.1)

hi,

i have a curious crash problem in release build of my application. it is kind of game platform which integrates several software packages for rendering, physics, in-game gui, etc.

the crash happens only sometimes and is not completely reproducable. i have built the app and all dependent libs with multi-threaded option and program data base ( /Zi, and the linker is also instrumented to generate debug info). so when the crash happens i can observe that in most cases two or three of my application threads are trying to either allocate or free memory. the debugger breaks on line :

malloc.c, line 211

when threads were trying to allocate memory.

some further info: i use only new and delete operators. the platform is win xp, i use vc2003 and win32 platform sdk for building the app (the app is build for console, in win32 app mode the same problem occurs as described above). some qa is already done on the code so it should be free of weak c++ constructs (i have used lint, and vc2005 beta2 compiler also gave me good ansi c++ compliance problems which i have already eliminated).

i cannot understand why the crash happens. any directions where i could search for the reason of the problem would be highly appreciated.

cheers
boto

[1256 byte] By [boto] at [2007-12-16]
# 1
There is a bug in your application that you will need to debug. A first step to help debug memory corruption issues is to use Application Verifier. See the link at:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/appverif/appverif/portal.asp

Debugging these kinds of issues can be very hard.

Ronald Laeremans
Visual C++ team

RonaldLaeremans at 2007-9-8 > top of Msdn Tech,Visual C++,Visual C++ General...
# 2
hi ronald,

i have used the tool you mentioned in your reply. it could not help me :-(

my general question is what else can be the reason that memory allocation or freeing using new and delete can cause a crash?

i know two obvious reasons:
1. trying to deallocate the same memory more that once,
2. allocating in one thread and trying to deallocate in another thread -- i.e. allocating and deallocating memory while not in same thread context.

do you know any other hidden os related reasons which i should consider?

thanks for your help
boto

boto at 2007-9-8 > top of Msdn Tech,Visual C++,Visual C++ General...
# 3

Allocating and deallocating in the different threads is absolutely safe, assuming that you are using thread-safe run-time library. Use /MT or /MD compiler switches to link with such library (thread-safe library is default in VC8.0).

Most probable cause of your problem is bug in your application. You can overwrite object you allocated in the heap, corrupting nearby memory. That memory may contain a list of free memory blocks. Allocation/deallocation routines will try to traverse those list and will crash.

Thanks,
Eugene

EugeneNalimov at 2007-9-8 > top of Msdn Tech,Visual C++,Visual C++ General...
# 4

hi eugene,

all used libs and the application are built with mt option. thank you very much for your hint on out of array bound problem, i will check the application for such potential bug.

cheers
boto

boto at 2007-9-8 > top of Msdn Tech,Visual C++,Visual C++ General...