Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ Visual-Studio
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 31-Aug-12 2:35am
Comments
pasztorpisti at 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 at 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!
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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[^]
  Permalink  
v4
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

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.
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 383
1 Richard Deeming 180
2 Sergey Alexandrovich Kryukov 171
3 Yogesh Kumar Tyagi 165
4 ChauhanAjay 156
0 Sergey Alexandrovich Kryukov 6,252
1 OriginalGriff 5,498
2 CPallini 2,473
3 Richard MacCutchan 1,627
4 Abhinav S 1,530


Advertise | Privacy | Mobile
Web04 | 2.8.140814.1 | Last Updated 31 Aug 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100