title: Is there any way of preventing application from crashing when heap is corrupted? - C programing language
body: <p>Sometimes in execution I get this error message in VS2010 when trying to free memory:</p>
  
  <blockquote>
    <p>Windows has triggered a breakpoint in [APPNAME].exe.</p>
    
    <p>This may be due to a corruption of the heap, which indicates a bug in [APPNAME].exe or any of the DLLs it has loaded.</p>
    
    <p>This may also be due to the user pressing F12 while [APPNAME].exe has focus.</p>
    
    <p>The output window may have more diagnostic information.</p>
  </blockquote>
  
  <p>Wich means something is wrong with heap or pointer.</p>
  
  <p>My issue is that this error crashes my app when it is built as a release.</p>
  
  <p>Also this is just a module of bigger application and when this crashes everithing goes down.</p>
  
  <p>I would like to be able to handle this error.</p>
  
  <p>From msdn on "free": </p>
  
  <blockquote>
    <p>If an error occurs in freeing the memory, errno is set with information from the operating system on the nature of the failure. For more information, see errno, _doserrno, _sys_errlist, and _sys_nerr.</p>
  </blockquote>
  
  <p>There is a <code>errno_t _get_errno( int * pValue );</code> function that returns error code.</p>
  
  <p>If I press continue on the error msg shown above this function returns error code.
  Using this code I can detect error, create call stack and exit my function softly.</p>
  
  <p>Is there any compiler switch or something to prevent aplication from crashing when free fails and allow me to exit it my way??</p>