Click here to Skip to main content
15,868,292 members
Please Sign up or sign in to vote.
5.00/5 (2 votes)
See more:
My application works fine in debug mode. But it crashes arbitrarily in release mode. Crash point shows that either they are crashing in malloc or free. Do I need to change any project settings or something else need to be done?
Awaiting prompt response.

Thanks,
Dipak
Posted
Comments
pasztorpisti 31-Aug-12 9:26am    
The reason for malloc/free to crash is usually heap corruption. This means that you use a pointer to an already deleted object and modify the pointed memory area. This is a common mistake. The other common bug is using a chunk of allocated memory and copying there with memcpy/strcpy by writing past the end of the allocated piece of memory. Another one is writing to an allocated array (like int array) by overindexing. These are the most common bugs. The memory in your heap consists of sections of the following 3 types: free memory, allocated memory, memory that is used by malloc/free to administer the allocated and free areas. If you overwrite something in the administrative areas then malloc/free crashes easily. I would mention that heap correction bugs are the most difficult to find besides thread synchronization bugs.
pasztorpisti 31-Aug-12 15:49pm    
Some help from M$: http://msdn.microsoft.com/en-us/library/w500y392%28v=vs.80%29.aspx
There are some other memory corruption seeker tools too that replace your malloc and free functions and do some trickery to find out if you wrote past your blocks, for example electric fence on linux. Use google to find tools/methods to detect memory corruption problems in C++. It won't be easy to catch bugs if the code quality is low, good luck!

I don,t Think that u have to change setting. i thing u have to check your code .
check malloc or free statement in release mode.
 
Share this answer
 
There maybe several reasons why a program doesnt work in Release but Debug mode. Most common from my experience are wrong versions of third-party libraries your application may depend on (e.g. linking debug libraries in release builds).

But as you described, your program fails at some memory management task (freeing memory). This is often the case because of some false memory management in your code. The fact that it works in Debug mode doesn't really prove that your code is error free, especially when dealing with allocating and freeing memory. This is because in Debug mode the memory is allocated differently. Lets say that the Debug mode is more forgiving because more memory is allocated then is actually needed (for debugging purpose). Therefore if you try to access some memory that should be illegal (because you didnt allocate it properly) it could still work in Debug mode because of the additionaly allocated memory.

I would suggest you to look at your code and see if there maybe false allocations (by logic). In your described case i think is very unlikely that your problem is related to Project/Compiler settings.

I can also suggest you this article on CP about this topic which may be of great help to you:
Debugging Release Mode Problems[^]

Also this one seems to be very helpfull:
Surviving the Release Version[^]
 
Share this answer
 
v4
The number 1 reason a program crashes in release mode but not debug mode is due to using an initialized variable. Uninitialized variables can have very different values in each mode so your program will behave differently when it used one of these. And make no mistake, if you use an unitialized variable your program *is* misbehaving in both modes, it just may not crash because of it in debug.

Make sure you initialize any variable before you use it.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900