当一个进程与其他进程结合运行时,会观察到句柄泄漏
我的一个可执行文件单独运行时打开大约 330 个句柄。当它与另一个特定进程结合运行时,它会泄漏许多句柄。
我使用 sysinternals 中的“句柄”实用程序来检查这两种情况下打开的所有句柄是什么。当此进程与其他特定进程结合运行时,它具有以下额外的句柄条目。
578: Process
57C: Thread
580: Process
584: Thread
588: Process
58C: Thread
590: Event
598: Process
59C: Thread
5A0: Process
5A4: Thread
5A8: Process
5AC: Thread
5B0: Process
5B4: Thread
5B8: Event
这样它就为进程、线程、事件打开了 400 个额外的句柄。 最终,这种泄漏导致应用程序崩溃。
我是 Windows 编程新手,请原谅我问非常基本的问题。 我将非常感谢这方面的任何帮助/建议。
- 句柄“Process”表示什么或意味着什么,在什么情况下它将被打开?
- 句柄“Thread”表示什么或意味着什么,在什么情况下它将被打开?
- 为什么两个进程单独组合会导致句柄泄漏? (这些进程大多是独立的)
- 我可以尝试什么来理解这种行为?
- 关于如何调试这种情况有什么建议吗?
- 有什么有用的工具可以进一步了解吗?
One of my executable is opening about 330 handles when it is run alone. Where as when it is run in combination with another specific process, it is leaking many handles.
I have used 'handle' utility from sysinternals to check what are all the handles open in both cases. When this process is run in combination with other specific process it is having the following handle entry's extra.
578: Process
57C: Thread
580: Process
584: Thread
588: Process
58C: Thread
590: Event
598: Process
59C: Thread
5A0: Process
5A4: Thread
5A8: Process
5AC: Thread
5B0: Process
5B4: Thread
5B8: Event
This way it has 400 extra handles opened for Process, Thread, Event.
Eventually this leak is causing the application to crash.
I am new to windows programming, please excuse me I am asking very basic questions.
I will really appreciate any help/ suggestion in this regard.
- What does the handle 'Process' indicate or mean, in what case it will be opened?
- What does the handle 'Thread' indicate or mean, in what case it will be opened?
- Why combination of the two processes alone causing the handle leak? (these Processes are mostly independent)
- What can I try to understand this behavior?
- Any suggestions on how to debug this kind of situation?
- Any useful tools to understand further?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是使用 CreateProcess() 函数时的一个非常经典的错误。最后一个参数 lpProcessInformation 返回一个 PROCESS_INFORMATION。如果您对返回的 hProcess 和 hThread 成员不感兴趣,则必须对它们调用 CloseHandle()。
It's a pretty classic bug when using the CreateProcess() function. The last argument, lpProcessInformation, gives you a PROCESS_INFORMATION back. You have to call CloseHandle() on the returned hProcess and hThread members if you are not interested in them.