A
Ashot Oganesyan
Hello,
I've just came across that the WTSQuerySessionInformation function on
Windows 2000 Professional SP4 (all fixes are installed) has a bug.
WTSQuerySessionInformation doesn't free memory and if I call it in the loop
the memory leakage can be huge!
This is an example:
/*
* This program demonstrates memory leak in WTSQuerySessionInformation()
* function.
*
* Application just calls WTSQuerySessionInformation() continiously in a
loop
* and frees any buffer which is returned. On W2K SP4 Workstation
* WTSQuerySessionInformation() always returns error ERROR_APP_WRONG_OS,
* sets pUserName to NULL (nothing to free). However, it can be seen by
* observing the application memory usage that virtual memory size
constantly
* grows by 4Kb. It seems to be some memory leak inside
* WTSQuerySessionInformation().
*
*
* OS: Windows 2000 Workstaion SP4 with all updates (up to 31 May 2005)
*
* Author: Sten ([email protected]), 2005
*/
#include <stdio.h>
#include <windows.h>
#include <wtsapi32.h>
void main (void)
{
LPTSTR pUserName;
DWORD dwBytesReturned;
while (1)
{
pUserName = NULL;
dwBytesReturned = 0;
if (!WTSQuerySessionInformation(
WTS_CURRENT_SERVER_HANDLE,
0,
WTSUserName,
&pUserName,
&dwBytesReturned))
{
printf("WTSQuerySessionInformation() failed [%08X]!\n",
GetLastError());
}
if (pUserName)
WTSFreeMemory(pUserName);
Sleep(100);
}
}
I've just came across that the WTSQuerySessionInformation function on
Windows 2000 Professional SP4 (all fixes are installed) has a bug.
WTSQuerySessionInformation doesn't free memory and if I call it in the loop
the memory leakage can be huge!
This is an example:
/*
* This program demonstrates memory leak in WTSQuerySessionInformation()
* function.
*
* Application just calls WTSQuerySessionInformation() continiously in a
loop
* and frees any buffer which is returned. On W2K SP4 Workstation
* WTSQuerySessionInformation() always returns error ERROR_APP_WRONG_OS,
* sets pUserName to NULL (nothing to free). However, it can be seen by
* observing the application memory usage that virtual memory size
constantly
* grows by 4Kb. It seems to be some memory leak inside
* WTSQuerySessionInformation().
*
*
* OS: Windows 2000 Workstaion SP4 with all updates (up to 31 May 2005)
*
* Author: Sten ([email protected]), 2005
*/
#include <stdio.h>
#include <windows.h>
#include <wtsapi32.h>
void main (void)
{
LPTSTR pUserName;
DWORD dwBytesReturned;
while (1)
{
pUserName = NULL;
dwBytesReturned = 0;
if (!WTSQuerySessionInformation(
WTS_CURRENT_SERVER_HANDLE,
0,
WTSUserName,
&pUserName,
&dwBytesReturned))
{
printf("WTSQuerySessionInformation() failed [%08X]!\n",
GetLastError());
}
if (pUserName)
WTSFreeMemory(pUserName);
Sleep(100);
}
}