title: Program crashing on exit
body: <p>Whenever I exit my program it gives me this exception "0xC0000022:  A process has requested access to an object, but has not been granted those access rights."</p>
  
  <p>It breaks right at the end of a function called _lock_file in _file.c.</p>
  
  <p>After trying to narrow down what the cause of the problem is I found out that it does not crash if I remove all fclose() function calls in my program then cleaning and rebuilding my program. Even if the function itself is never called it will still crash. Obviously this solution is not ideal.</p>
  
  <p>When I tried to use fstream instead it produced a similar crash at the start of the program.</p>
  
  <p>It's also worth mentioning that my program uses SDL.</p>
  
  <p>Edit: Someone requested a minimal example and this is what I cam up with.</p>
  
  <p>main.cpp</p>
  
  <pre><code>#include &lt;stdlib.h&gt;
  #include &lt;SDL.h&gt;
  /*...*/
  #pragma comment(lib, "SDL.lib")
  #pragma comment(lib, "SDLmain.lib")
  /*...*/
  int main( int argc, char **argv)
  {
      if(false)
          fclose(NULL);
      return 0;
  }
  </code></pre>
  
  <p>draw.cpp</p>
  
  <pre><code>/*...*/
  </code></pre>
  
  <p>If I run this it will crash on exit just like I mentioned above. And yes the draw.cpp is completely commented out, but if I remove it from the project the program will run fine. All other files were removed from the project.</p>
  
  <p>Edit2: In response to karlphillip I decided to double check if it is actually running and it seems that it is actually crashing at the start with this example.</p>
  
  <p>Also it is a Win32 project.</p>