I have the following code in my program:
EnterCriticalSection(&critsec[x]);
// stuff
LeaveCriticalSection(&critsec[x]);
It works fine 99.999% of the time but occasionally a handle seems to get left behind. Now I have done the obvious things like make sure that x did not change value between the enter and make sure that there isn't any "return" or "break" inside "// stuff" but I was wondering if there could be something else that would cause an enter/leave pair to leave a handle behind. Perhaps running out of memory or overflowing some counter in the OS or whatever.
EDIT: I am new to C++, the program has only recently been converted from C. It has no exceptions anywhere in the entire program.