1

Possible Duplicate:
Why would fclose hang / deadlock? (Windows)

when i call .close i get a crash. enter image description here

What i do is save a file, close it and load it immediately. This is for debugging reasons to see if my serialization code is working (it has many checks and they all pass)

I did some debugging and i cant figure out what may cause it. What i notice is

  • It crashes on a specific file
  • Running the file alone wont crash
  • Removing a multiple file will decrease the chance of it from crashing (but i am unsure if it has relevant). From 100% to 50% or 30% depending on how many i remove.
  • The less files i have the less likely it will happen. But it always happens on that specific file no matter the amount of files
  • Other files crash as well but in a different bat series

But whats bothering me is - The file seems to load properly. I put in a debug counter and it is incremented the correct amount of times. - The file handle is alive for only one function. The function loads it closes the file and returns the parsed data. Why is it affected by other files in the bat series

In release mode if i run the files in the VS IDE its fine. When i press ctrl F5 to run outside it crashes. But running the single file with release outside of the IDE is fine as well.

I'm very confused.

Community
  • 1
  • 1
  • 1
    Heap corruption caused by data specific buffer overrun. We had a question just like this last week (going to look for it). – Ben Voigt Jun 01 '11 at 13:37
  • BTW, next time you should ask the debugger to check the Microsoft public symbol servers, that will get you the names of the functions from kernel32. – Ben Voigt Jun 01 '11 at 13:40
  • @Ben: How do i do that? When it crashes i tried clicking the first option (check online) and nothing seemly happened. The other option is debug and close. –  Jun 01 '11 at 13:52

1 Answers1

1

As Ben Voigt says, it's probably a problem elsewhere in the program (perhaps in a seemingly unrelated place), not ifstream::close() itself. Stack overflow (the problem, not this site), wayward pointer, writing past the end of an array -- these are common causes of such problems.

Community
  • 1
  • 1
metal
  • 6,202
  • 1
  • 34
  • 49
  • After thinking about it. I very much doubt it happens in the save/load code. Is it possible for the corruption to occur before opening the file? My serialize code is generated and i have a padding before and after each write (it blew up the file size). It all checks out. Other places in code i check casting extensively to see if its the proper type. It seems good so far. Where are the possible places this could occur? –  Jun 01 '11 at 13:56
  • I also check if i set variables before writing them and before using http://stackoverflow.com/questions/6079052/property-like-features-in-c/6080497#6080497 this problem is annoying and mysterious. It must not be in the serialization code –  Jun 01 '11 at 13:59