Microsoft Knowledge Base Article
This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved.
Terms
of Use |
Trademarks
Article ID: 2384321 - Last Review: September 17, 2010 - Revision: 1.0
You may see memory leak when running ICMP multithread application on post-Vista OS
If you are developing ICMP multithread application, you may notice private bytes growing steadily and constantly when running on post-Vista OS, including Vista, Window Server 2008 and Windows 7.
For example:
int _tmain(int argc, _TCHAR* argv[])
{
while(true){
_beginthread(SendPing, 0, NULL);
Sleep(50);
}
return 0;
}
void SendPing(LPVOID lpParameter)
{
HANDLE hIcmpFile; // Handle for ICMP echo requests
BOOL bRetVal;
hIcmpFile = IcmpCreateFile();
if (hIcmpFile == INVALID_HANDLE_VALUE)
{
//Print message
}
else
{
// close the echo request file handle
bRetVal = IcmpCloseHandle(hIcmpFile);
if(bRetVal)
{
//print message
}
else
{
//print message
}
}
_endthread();
}
There is a bug in IcmpCreateFile/IcmpCloseHandle function with post-Vista OS, including Vista, Win2K8 and Win7. The growth of memory usage is due to leak of critical section object. We verified the memory leak issue does NOT occur or XP/Win2K3 due to different implement. The bug has been report and confirmed by Product Group.
A workaround is to add one more IcmpCreateFile call in the function as below:
int _tmain(int argc, _TCHAR* argv[])
{
HANDLE hIcmpFile = IcmpCreateFile(); //Add this line
while(true){
_beginthread(SendPing, 0, NULL);
Sleep(50);
}
return 0;
}
Note This is a "FAST PUBLISH" article created directly from within the Microsoft support organization. The information contained herein is provided as-is in response to emerging issues. As a result of the speed in making it available, the materials may include typographical errors and may be revised at any time without notice. See
Terms of Use
(http://go.microsoft.com/fwlink/?LinkId=151500)
for other considerations.
APPLIES TO
- Windows Vista Enterprise
- Windows Server 2008 Enterprise
- Windows 7 Enterprise
Community Feedback System
Very often, it takes hours to solve a problem. Very often, you've looked high
and low, and have tried a lot of solutions. When you finally found it, chances
are, it was because someone else helped you. Here's your chance to give back.
Use our community feedback tool to let others know what worked for you and what
didn't.
Please also understand that the community feedback system is not warranted to be
correct, it's simply a system that we've built to let people try and help each
other. If something in a feedback response doesn't make sense to you, or you're
not comfortable making changes that the feedback talks about (like registry
edits), please consult a professional.
Thank you for using kbAlertz.com Feedback System.
-- Scott Cate