I have an incredibly weird problem with a small console application I've been writing. It's basically a console application to create/extract an archive type I've created myself.
What happens is that everything works fine as long as single-threaded DEBUG is turned on at my Visual Studio .NET compiler options. When I set it to single-threaded (default in release configuration), the program crashes at seamingly random lines (it crashes just after a cout << "test" << boolvarhere; line, and if I remove that line it just crashes at the beginning of the next while loop) with an error about heap allocation.
To be precise, the error I get is:
Unhandled exception at 0x77f485c0 in KARTool.exe: 0xC0000005: Access violation writing location 0x454e2e20.
The debugger points at line "return HeapAlloc(_crtheap, 0, size);" in malloc.c.
Also, the program only seems to crash if I enter a string of exactly 7 characters in one of the cin calls a few lines earlier. If I enter a 8-char string or a 6-char string the program continues but I'm sure it will crash eventually. Right now I've commented about 80% of the whole program and it still crashes after a few lines.
I don't use threads or anything and I haven't included any platform-specific headers. I only used the C++ standard library and a few functions from stdio.h/string.h.
As said earlier: I can fix the problem by turning single-threaded debug on, but that substantially increases the size of my executable and I want to get rid of this problem once and for all, not run from it. I had the same thing with one of my previous projects as well and I couldn't fix it back then either.