ApplicationVerifier未检测到句柄泄漏,该怎么办? [英] ApplicationVerifier is not detecting handle leaks, what do I do?

查看:122
本文介绍了ApplicationVerifier未检测到句柄泄漏,该怎么办?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我确实正确选择了可执行文件,因为我可以使它响应我所做的某些事情.但是我无法让ApplicationVerifier正确检测到句柄泄漏.

I did select the executable correctly, because I can get it to respond to certain things I do. But I can't get ApplicationVerifier to properly detect a handle leak.

这里是一个例子:

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未检测到此.

ApplicationVerifier doesn't detect this.

我该怎么做才能检测到以上问题?

What can I do to detect the above problem?

推荐答案

您的代码是否仅通过CreateFile创建句柄?如果是这样,您可以将这些方法宏化为执行自定义实现的泄漏检测的版本.这是很多工作,但可以完成工作.

Is your code only creating handles through CreateFile? If so you can just macro these methods out to versions that do custom implemented leak detection. It's a lot of work but it will get 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
}

在程序结束时,您需要调用CheckForLeaks.就像我说的那样,需要做很多工作,但这可能会对您的scenairo有所帮助.

At the end of your program you'd need to call CheckForLeaks. Like I said though, quite a bit of work but it may help with your scenairo.

这篇关于ApplicationVerifier未检测到句柄泄漏,该怎么办?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆