ApplicationVerifier doesn't detect handle leaks, what should I do?

I chose the executable correctly because I can get it to answer some of the things I do. But I cannot get the ApplicationVerifier to properly detect the descriptor leak.

Here's an example:

int APIENTRY _tWinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPTSTR    lpCmdLine,
                     int       nCmdShow)
{
    HANDLE hFile = CreateFile(_T("C:\\test.txt"), GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
    return 0;
}

      

ApplicationVerifier does not detect this.

What can I do to detect the above problem?

0


source to share


1 answer


Is your code just creating descriptors via CreateFile? If so, you can simply use the macros of these methods for versions that perform selective leak detection. It's a lot of work, but it gets the job done.

#if DEBUG
#define CreateFile DebugCreateFile
#define CloseHandle DebugCloseHandle
#endif
// in another cpp file
#undef CreateFile
#undef CloseHandle
HANDLE DebugCreateFile(...) {
  HANDLE real = ::CreateFile(...);
  TrackHandle(real);
  return real;
}
void DebugCloseHandle(HANDLE target) {
  if (IsTracked(target)) { Untrack(target); }
  ::CloseHandle(target);
}
void CheckForLeaks() {
  // Look for still registered handles
}

      



At the end of your program, you will need to call CheckForLeaks. As I said, quite a bit of work, but it might help with your scenario.

+1


source







All Articles