Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

You may see memory leak when running ICMP multithread application on post-Vista OS


Symptoms

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();

}

 

↑ Back to the top


Cause

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.

↑ Back to the top


Resolution

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;
}

 

↑ Back to the top


Keywords: vkball, kb

↑ Back to the top

Article Info
Article ID : 2384321
Revision : 1
Created on : 1/8/2017
Published on : 9/17/2010
Exists online : False
Views : 806