Memory leak in WTSQuerySessionInformation on W2K Prof

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);
}
}
 
Joined
Feb 2, 2007
Messages
1
Reaction score
0
WTSQuerySessionInformation return ERROR_APP_WRONG_OS on Windows 2000

Hello,


I don't know if you got any suggestions for what you describe.
On Windows 2000 Server with TSE, i get the same error code as you when I call WTSQuerySessionInformation. The error is ERROR_APP_WRONG_OS.

Please let me know how you resolved your trouble.

Thank you.

Augustin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top